I’m reviewing a site that a previous developer had worked on and trying to pick up where they left off.
It seems they had created two post categories called “Upcoming Events” (slug = upcoming-events) and “Previous Events”(slug= previous-events). They also created a custom post type called “Events”. In the custom post-type editor for anything under events “Events”, both the “Upcoming Events” and “Previous Events” categories appear to the right of the editor under Categories. Each event has one of those 2 categories checked off.
Open your functions.php file and try something like this:
add_filter('pre_get_posts', 'query_post_type');
function query_post_type($query) {
if(is_category() || is_tag()) {
$post_type = get_query_var('post_type');
if($post_type)
$post_type = $post_type;
else
$post_type = array('post','custom-post-type-name'); // add the name of your custom post type
$query->set('post_type',$post_type);
return $query;
}}
thanks but that did not work. i added this code exactly to the bottom of my functions.php file, in a new line right after the previous function ended with ?>
<?php
add_filter('pre_get_posts', 'query_post_type');
function query_post_type($query) {
if(is_category() || is_tag()) {
$post_type = get_query_var('post_type');
if($post_type)
$post_type = $post_type;
else
$post_type = array('events','upcoming-events'); // add the name of your custom post type
$query->set('post_type',$post_type);
return $query;
}}
?>
that link just brings up a designed post and that’s it. It’s not even the most recent and its not the only one in the Events category. I’m looking for an archive page of all the events.