I have custom meta st_date and end_date
I want to select the post with both of these conditions are true for :
1- end_date = “some date”
2- st_date = “some date”
3-Also I need it to select by title
4-Then used the result inside the WordPress loop.
if ( have_posts() ) : ?>
<?php get_template_part('loop'); ?> //etc..
Here is my draft code:
$st_date_s = 'something';
$end_date_s = 'something';
$pageposts = get_posts(
array(
'post_title' => 'something'
'post_type' => 'something',
'post_status' => 'publish',
'meta_query' => array(
array(
array( 'key' => 'st_date', 'value' => $st_date_s, 'compare' => '=' ),
array( 'key' => 'end_date', 'value' => $end_date_s, 'compare' => '=' )
)
),
)
);
?>
<?php global $site_url;
if ( have_posts() ) : ?>
<?php get_template_part('loop'); ?>
<?php else : ?>//etc..
Also why ‘post_title’=> doesn’t work?
You’re missing a
relation
argument, and have one-too-manyarray()
s. Since you want both conditions to be true, you should useAND
:Read more about custom field parameters in the docs.