I am trying to use WP_Query to search through posts BUT I want to also search by post_title as well, which is why I tried using meta_query in my arguments array. I want to actually do more than just search that field but also fields from using the get_post_custom() function.
When I use the meta_query argument it doesn't return any results.
Here is what I have so far:
$args = [
'post_type' => 'listing_type',
'posts_per_page' => -1,
'meta_query' => array(
array(
array(
'key' => 'post_title',
'value' => '"'.$this->vals['name'].'"',
'compare' => 'LIKE',
)
)
)
];
$q = new WP_Query($args);
and when I try and get values via using this loop below, nothing is returned:
<?php if($q->have_posts()): ?>
<?php while($q->have_posts()): $q->the_post();?>
<?php
$custom_fields = get_post_custom(get_the_ID());
$featured = $custom_fields['featured'][0];
$front_page = $custom_fields['frontpage'][0];
$img = $custom_fields['image'][0];
$location = $custom_fields['map_location'][0];
$src = wp_get_attachment_image_src(get_post_thumbnail_id($q->ID), array(300,300), false, '');
the_title();
?>
<?php endwhile; ?>
<?php endif; ?>
and I am searching using keywords I know are in the title of my posts and nothing is still showing up
Aucun commentaire:
Enregistrer un commentaire