【问题标题】:Filter certain data on post object ACF过滤帖子对象 ACF 上的某些数据
【发布时间】: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-&gt;ID); 这个字段使用的是 post object ACF
  • 我也尝试过这样的事情:$posts = get_field('t2_first_name',$post-&gt;ID); if ($posts): foreach ($posts as $post): setup_postdata($post); $query = $post_title-&gt;ID; endforeach; wp_reset_postdata(); endif; 但它没有发送任何数据

标签: wordpress advanced-custom-fields


【解决方案1】:

我找到了解决办法:

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

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

【讨论】:

    猜你喜欢
    • 2022-11-24
    • 1970-01-01
    • 1970-01-01
    • 2012-11-28
    • 1970-01-01
    • 1970-01-01
    • 2020-11-21
    • 2019-01-15
    • 2019-07-16
    相关资源
    最近更新 更多