SQL, .
: meta_query wordpress , , "AND" "OR".
, Wordpress /content = "myContent" aioseop_keyword "myContent". ( ) , SEO.
To get around this, I make two queries. It sounds simple, BUT: Loop did not want to recognize messages, despite the fact that there are entries in the $ post object. I found this solution by looking at the has_posts () function : it refers to other variables, not just the $ post object.
$term = get_search_query();
$wordpress_keyword_search =& new WP_Query(array(
's' => $term,
'showposts' => -1
));
foreach ($wordpress_keyword_search->posts as $post_)
$exclusion[] = $post_->ID;
$aioseop_keyword_search =& new WP_Query(array(
'post__not_in' => $exclusion,
'post_type' => 'any',
'showposts' => -1,
'meta_query' => array(
array(
'key' => '_aioseop_keywords',
'value' => $term,
'compare' => 'LIKE',
)
)
));
$wordpress_keyword_search->posts = array_merge($wordpress_keyword_search->posts, $aioseop_keyword_search->posts );
$wordpress_keyword_search->found_posts = $wordpress_keyword_search->found_posts + $aioseop_keyword_search->found_posts;
$wordpress_keyword_search->post_count = $wordpress_keyword_search->post_count + $aioseop_keyword_search->post_count;
Then use this in a simple loop:
if ($wordpress_keyword_search->have_posts()) {
while($wordpress_keyword_search->have_posts()) {
$wordpress_keyword_search->the_post();
the_title();
the_content();
}
} else {
echo '<p>Sorry, no posts found</p>';
}
source
share