I'm pretty sure I need to do some sort of custom query, but not sure about the best way to go with it.
I have an author page. It needs to display that author's posts. That's fine, I can do that. I need to amend the query so that it displays the author's posts as well as posts tagged to that author's name.
So I imagined the query something like this
query_posts("author=$author_name||tag=$author_name");
I figured that I could set up the query using WP_Query and feeding it the meta_query
with the relation OR
but that only returned posts by the author and ignored ones that were tagged:
$args = array(
"showposts" => "$show_num_posts",
"meta_query" => array(
"relation" => "OR",
array(
"author" => "$authID"),
array(
"tag" => "$nametag"
)
)
);
$the_query = new WP_Query($args);
I figure that it's ignoring it because it's found ones by the author and I've specified OR
when what I really need is some sort of AND/OR
. I've had a look at this example but can't seem to recreate that user's solution to fit my needs. I just keep breaking the whole thing.
global $wpdb;
$args = $wpdb->get_results($wpdb->prepare(
"
SELECT $wpdb->posts.*
FROM $wpdb->posts, $wpdb->postmeta
WHERE ($wpdb->posts.author = $authID)
OR ($wpdb->postmeta.tag = $nametag)
"
)
);
foreach ( $args as $post ) : setup_postdata($post);
Is there something out there you could point me towards? There has to be an easier way to do this. I'm probably over-complicating it and there's a really simple (probably in-built) way of doing it I've just missed. Searching the codex returned nothing useful though.
meta_query
is incomplete, which could be a problem, but I can't tell what you are trying to do. What does "tagged to that author's name" mean? How are the posts tagged?