What you’re trying to achieve is a LIKE
query. But you’re using the compare
arguments that are only present for meta_query
arguments. You need to utilize a filter like the following:
add_filter( 'posts_where', 'wpse120358TitleLike', 10, 2 );
function wpse120358TitleLike( $where, &$wp_query )
{
global $wpdb;
if (
'post' === $wp_query->get( 'post_type' )
AND $wp_query->get( 'name' )
// add further restriction arguments here:
// AND ...
)
{
$where .= $wpdb->prepare(
' AND %s LIKE %s',
"{$wpdb->posts}.post_title",
'%'.like_escape( $wp_query->get( 'name' ) ).'%'
);
}
return $where;
}
Note that this is not a tested script. It’s meant as a guideline that can be built upon.