我的元查询有很大的问题。我想过滤我的帖子,我需要查询以将 post_title 与我的 $_POST 值进行比较。代码:
function postsFilter(){
$args = array(
'post_type' => 'posts',
'meta_query' => array(
'relation' => 'AND'
)
);
if( isset($_POST['year']) && $_POST['year'] )
$args['meta_query'][] = array(
'key' => 'year',
'value' => $_POST['year'],
'compare' => '='
);
if( isset($_POST['theme']) && $_POST['theme'] )
$args['meta_query'][] = array(
'key' => 'theme',
'value' => $_POST['theme'],
'compare' => '='
);
if( isset($_POST['member']) && $_POST['member'] )
$args['meta_query'][] = array(
'key' => 'member_relation',
'value' => ``.$_POST['member'].``,
'compare' => 'LIKE'
);
$query = new WP_Query( $args );
echo "<script>
var posts_p = '" . json_encode( $query->query_vars ) . "',
current_page_p = " . 1 . " ,
max_page_p = " . $query->max_num_pages . ";
console.log(current_page_p, max_page_p);
</script>";
if( $query->have_posts() ) :
while( $query->have_posts() ): $query->the_post();
get_template_part('template-parts/content', 'posts');
endwhile;
if ( $query->max_num_pages > 1 )
echo '<div class="button-load-more_p btn-load-more text-center mx-auto w-100"><a class="btn btn-primary btn-md btn-with-icon fade-in full-visible load-more"><span>Load more</span></div></a></div>';
wp_reset_postdata();
else :
echo 'No publications found';
endif;
die();
}
这里存在问题:
if( isset($_POST['member']) && $_POST['member'] )
$args['meta_query'][] = array(
'key' => 'member_relation',
'value' => $_POST['member']
'compare' => 'LIKE'
);
因为我不知道如何编写这部分查询,成员关系是 Wordpress 中的 POST OBJECT 类型文件,我需要将 $_POST['member'] 与 post_title 值进行比较(也许我错了?)
$member = get_field('member_relation', $post_object->ID);
$member->post_title;
是否可以编写此查询?请给我任何建议或解决我的问题的示例。