【发布时间】:2020-04-16 14:44:37
【问题描述】:
想问。
我有使用 post 对象的 ACF 字段。我想使用 url 从 post 对象字段发送值。结果显示它发送了所有详细信息。
我做的是:
$field['choices'] = array();
$choices = get_field('t2_first_name',$post->ID);
$query = http_build_query(array('aParam' => $choices));
$cpage = home_url('/?datasend='.$query);
//button to send data in url
echo '<a class="cst-btn cst-btn-'.$color.'" href="'.$cpage.'" >Submit</a>';
结果展示:
{"post_author":"3998","post_date":"2020-04-05 05:23:10","post_date_gmt":"2020-04-04 21:23:10","post_content":"","post_title":"183303P","post_excerpt":"","post_status":"publish","comment_status":"closed","ping_status":"closed","post_password":"","post_name":"183303p","to_ping":"","pinged":"","post_modified":"2020-04-05 05:23:10","post_modified_gmt":"2020-04-04 21:23:10","post_content_filtered":"","post_parent":"0","guid":"http:\/\/www.mekcas.a2hosted.com\/trainer\/183303p\/","menu_order":"0","post_type":"trainer","post_mime_type":"","comment_count":"0","filter":"raw"}
如何仅过滤使用 url 发送的“post_title”?有人可以帮忙吗?
【问题讨论】:
-
您希望按钮中的 href 看起来如何?
-
我想看起来像这样:[link](www.example.com/?datasend=183303P) @Tokant
-
所以你想在访问者点击提交链接时捕获查询变量“datasend”,并通过“post_title”过滤结果?
-
是的。但是 post_title 是基于 post 对象
$choices = get_field('t2_first_name',$post->ID);这个字段使用的是 post object ACF -
我也尝试过这样的事情:
$posts = get_field('t2_first_name',$post->ID); if ($posts): foreach ($posts as $post): setup_postdata($post); $query = $post_title->ID; endforeach; wp_reset_postdata(); endif;但它没有发送任何数据
标签: wordpress advanced-custom-fields