Community Forums › Forums › Archived Forums › General Discussion › Sorry, no content matched your criteria after creating custom post type
- This topic has 5 replies, 2 voices, and was last updated 7 years, 11 months ago by
iefdelaender.
-
AuthorPosts
-
December 26, 2015 at 10:50 am #174834
iefdelaender
MemberHello,
I use the modern studio pro theme.
I'm trying to make a custom post type but I've get an error "Sorry, no content matched your criteria" when I click to a category or tag. I filled in a category or tag when I input new content into the custom posts. I see that in my table that a category or tag is associated.
This is my code:
<?php
/*
Plugin Name: Waterlelie Custom Post Type
Plugin URI: http://wpbeaches.com/create-custom-post-types-in-genesis-child-theme-in-wordpress/
Description: Custom Post Waterlelies database
Author:
Version:1
Author URI:
*//*
This code is a plugin to create a Custom Post Type in WordPress, it can be used with any WordPress theme.
The action initialises the function below it.
This example uses the term 'Events' as its name, a search and replace will allow any name to be used, making sure plural and singular versions of the name are replaced.
Also replace the name in 'rewrite' and in the 'register_post_type' function.
For non-Genesis themes the 'genesis-cpt-archives-settings' can be removed from the supports array.
To activate this as a plugin just add to wp-contents/plugins and activate in Dashboard
*/function create_custom_post_type() {
$labels = array(
'name' => __( 'Waterlelies' ),
'singular_name' => __( 'Waterlelies' ),
'all_items' => __( 'All Waterlelies' ),
'add_new' => _x( 'Add new Waterlelie', 'Waterlelies' ),
'add_new_item' => __( 'Add new Waterlelie' ),
'edit_item' => __( 'Edit Waterlelie' ),
'new_item' => __( 'New Waterlelie' ),
'view_item' => __( 'View Waterlelie' ),
'search_items' => __( 'Search in Waterlelie' ),
'not_found' => __( 'No Waterlelies found' ),
'not_found_in_trash' => __( 'No Waterlelies found in trash' ),
'parent_item_colon' => ''
);
$args = array(
'labels' => $labels,
'public' => true,
'has_archive' => true,
'menu_icon' => 'dashicons-admin-users',
'rewrite' => array( 'slug' => 'waterlelies' ),
'taxonomies' => array( 'category', 'post_tag' ),
'hierarchical' => true,
'query_var' => true,
'menu_position' => 5,
'supports' => array( 'genesis-cpt-archives-settings', 'thumbnail' , 'custom-fields', 'excerpt', 'comments', 'title', 'editor')
);
register_post_type( 'Waterlelies', $args );
}add_action( 'init', 'create_custom_post_type' );
//flush the permalinks - ref - https://codex.wordpress.org/Function_Reference/register_post_type#Flushing_Rewrite_on_Activation
function my_rewrite_flush() {
// First, we "add" the custom post type via the above written function.
// Note: "add" is written with quotes, as CPTs don't get added to the DB,
// They are only referenced in the post_type column with a post entry,
// when you add a post of this CPT.
create_custom_post_type();// ATTENTION: This is *only* done during plugin activation hook in this example!
// You should *NEVER EVER* do this on every page load!!
flush_rewrite_rules();
}
register_activation_hook( __FILE__, 'my_rewrite_flush' );December 26, 2015 at 10:54 am #174835Brad Dalton
ParticipantYou can use this code to add a custom post type via your functions file.
After adding the code, re-save your permalinks.
December 27, 2015 at 4:32 am #174859iefdelaender
MemberIt didn't work. Still get the message "no content matched" I used the code in the link you give me. I tried an other theme 'genesis sample theme and I deactivated all my plugins and re-saved the permalinks but nothing works.
December 27, 2015 at 7:33 am #174862Brad Dalton
ParticipantDecember 28, 2015 at 6:08 am #174940iefdelaender
Memberthis is the archive and when you click on a tag or category you will see the no content matched message
December 28, 2015 at 9:23 am #174946iefdelaender
MemberI've found the solution of this problem:
https://wpbeaches.com/show-custom-post-types-category-archive-page/function themeprefix_show_cpt_archives( $query ) { if( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) { $query->set( 'post_type', array( 'post', 'nav_menu_item', 'custom-post-type-name' )); return $query; } } add_filter( 'pre_get_posts', 'themeprefix_show_cpt_archives' );
-
AuthorPosts
- The topic ‘Sorry, no content matched your criteria after creating custom post type’ is closed to new replies.