I have a small problem with WP_Query
. I want to get the posts filtered by category and with similar project name (like query), so I’m trying this code:
$args=array(
'post_type' => 'post',
'post_status' => 'publish',
'category_name' => 'projects',
'name__like' => 'Proj');
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post();
echo '<div class="Entradas">'.get_the_title().'</div>';
endwhile;
}
wp_reset_query();
Actually it displays the projects filtered by category, but the name__like
is not working.
Any suggestions to fix this?
Revisited and simplified answer:
You can try:
where we’ve created the
_name__like
input argument. It supports wildcard*
, for example:Note that draft posts don’t have
post_name
set before they’re published.We use the following plugin to support this new argument:
I did not use any
name__like
or filters. This is how I finally made it:So I get the posts and I check if their title or content contains the value I´m looking for, Im sure there must be solutions using WP_Query options but I prefer this way.