Skip to content

Commit

Permalink
fix: don't modify post type archive pages
Browse files Browse the repository at this point in the history
  • Loading branch information
dustin-jw committed Nov 7, 2023
1 parent 3426f2d commit 44ede79
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
40 changes: 40 additions & 0 deletions src/php/inc/custom-post-types/recipe.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
/**
* File for Registering Recipes
*/

/**
* Register Recipes
*
* @return void
*/
function custom_post_type_recipes() {
$labels = array(
'name' => 'Recipes',
'singular_name' => 'Recipe',
'all_items' => 'All Posts',
);
$args = array(
'label' => 'Recipes',
'description' => 'Custom post type for Recipes',
'labels' => $labels,
'supports' => array( 'title', 'editor', 'comments', 'revisions', 'trackbacks', 'author', 'excerpt', 'thumbnail' ),
'taxonomies' => array( 'category', 'post_tag' ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_icon' => 'dashicons-admin-post',
'show_in_rest' => true,
'menu_position' => 5,
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'post',
);
register_post_type( 'recipe', $args );
}
add_action( 'init', 'custom_post_type_recipes', 0 );
6 changes: 5 additions & 1 deletion src/php/inc/setup-queries.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ function sb_query_vars_filter( $vars ) {
* @return object
*/
function enable_custom_posts_in_archives( $query ) {
if ( ! $query->is_admin() && ( $query->is_archive() || ( $query->is_home() && $query->is_main_query() ) ) ) {
if ( $query->is_admin() || $query->is_post_type_archive() ) {
return $query;
}

if ( $query->is_archive() || ( $query->is_home() && $query->is_main_query() ) ) {
$query->set(
'post_type',
array(
Expand Down

0 comments on commit 44ede79

Please sign in to comment.