如何在wordpress meta_query中的子字段用于wp查询参数?

问题描述

您好,我正在尝试向我的wp查询参数添加Meta_query。

这是我的帖子Meta

$post_options = get_post_meta( get_the_ID(),'post_options')[0];
print_r($post_options);

产生如下数组:

Array ( [on_demand] => true [featured_video] => https://example.com/1234 )

这是我的代码,正常的循环工作正常,但是在添加Meta_query时中断了:

//helper function from https://www.advancedcustomfields.com/resources/query-posts-custom-fields/
function my_posts_where( $where ) {
    $where = str_replace("Meta_key = 'post_options_%","Meta_key LIKE 'post_options_%",$where);
    return $where;
}
add_filter('posts_where','my_posts_where');

    $args = array(  
        'post_type' => 'event','post_status' => 'publish','posts_per_page' => -1,'order' => 'DESC','Meta_query'    => array(
            array(
                'key'     => 'post_options_%_on_demand','value'   => 'true','compare' => '='
            )
        )  
    );
    
        // The Query
        $the_query = new WP_Query( $args );

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)