OR operator is not working for both conditions, only check first value if true then code executed and if first is false then not check 2nd condition and return else output.
I also try with LIKE compare, but then it's check custom fields value with all other values and if This CF value's contain by any other string CF value then it's become true.
<?php
$posts = get_posts(array(
'numberposts' => 14,
'post_type' => 'post',
'post_status' => 'publish',
'category_name' => 'travel',
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'Swimming',
'value' => get_post_meta(get_the_ID(), 'Swimming',true),
'compare' => 'IN'
),
array(
'key' => 'Boat',
'value' => get_post_meta(get_the_ID(), 'Boat',true),
'compare' => 'IN'
))));
if($posts) {
foreach($posts as $post) {
?>
<?php the_title(); ?>
<?php
}
}
else {
?>
<?php echo "No Update";
}
?>
value
should just be the value you're looking for - i.e. change theget_post_meta()
calls to justSwimming
andBoat
. See if that helps.swimming
and aboat
term,meta_query
is slow and doesn't scale well as the site gets larger. Post meta tables were designed for fetching data when you already know the post you want, it was never intended for searches like this. That's what taxonomy tables andtax_query
is for. If you need to store data put it in post meta, but if you need to search/find/filter/query for data on a post that isn't in its main content/title, put it in a taxonomyget_posts
is slower thanWP_Query
as it's uncached, you need to add thesuppress_filters
parameter and set it tofalse
so that caching plugins and filters can speed it up