Writing a correct query?
-
I can’t seem to figure out how to construct the correct query
I made a custom taxonomy named “spotlight” which then has five or so terms. I want to act upon the taxonomy when someone views one of the spotlight archives. I only care about its value being “true” not which spotlight is viewed. This works if viewing a spotlight, but throws an error if viewing any non-spotlight archive (Warning: Undefined array key “spotlight”). Right now I have it beneath other taxonomies so that other taxonomies exit before reaching it, but that is bad practice. How do I perform a correct query?
add_action('pre_get_posts','tweak_archive_post_order')
function tweak_archive_post_order($query)
{if ($query->is_main_query() && is_archive() && $query->query_vars['category_name'] == 'skirted')
{$query->set( 'posts_per_archive_page','-1');
$query->set( 'orderby','manual_sort_order');
$query->set( 'meta_key','manual_sort_order');
$query->set( 'order','ASC');
}
[....]
elseif ($query->is_main_query() && is_archive() && ($query->query_vars['spotlight']))
{$query->set('posts_per_archive_page','-1');
$query->set('orderby','date');
$query->set('order','ASC');
}
}The page I need help with: [log in to see the link]
The topic ‘Writing a correct query?’ is closed to new replies.