首页 > 解决方案 > 过滤帖子对象 ACF 上的某些数据

问题描述

想问。

我有使用 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”?任何人都可以帮忙吗?

标签: wordpressadvanced-custom-fields

解决方案


我找到了一个解决方案:

if( $post_object ):
    $name = get_the_title($post_object->ID);
wp_reset_postdata();
endif;

这对我有用。它仅过滤 post_object 的标题(基于选定的 ACF 字段)


推荐阅读