I am using this code to get stuff based on my custom field and custom content type.
$searchTerm = 'bestafricanvideos';
$args = array(
'post_type' => 'sitemaps',
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => 'cstm_sitemap_url',
'value' => $searchTerm,
'compare' => 'LIKE',
),
)
);
print_r($args);
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) :
while ( $the_query->have_posts() ) : $the_query->the_post();
$video_url = rwmb_meta('cstm_sitemap_url');
print_r($video_url);
endwhile;
else :
echo "No video URL found";
exit;
endif;
wp_reset_postdata();
print_r($video_url);
And the problem is that nothing is returned.
If I remove the metaquery I get a lot of results.
So, I think the problem is that I have stored the custom meta field in db as an url, for example: http://bestafricanvideos.com/top10.html
and my search term is bestafricanvideos
so, maybe the LIKE cannot grab it and only something like this: http:// bestafricanvideos .com/top10.html
will be grabbed?
Any idea how to fix the meta_query so I can grab stuff that conatain the search term in a longer string (or part of a string)?
LIKE
query will be a wildcard query--%searchterm%
-- so it should match any of the strings you provided as samples. Exactly where in the code does is "return nothing"? I assume you've debugged by, for example, checkingvar_dump($the_query->request);
?'%http://bestafricanvideos.com/videos\\_top\\_10.xml%' )