Display custom post type in template

Create custom page template The first step is to create a custom page template to hold the code. For example, name the file template-cpt-list.php: <?php /** * Template Name: Custom Post Types List */ get_header(); // Custom code will go here get_footer(); ?> Create list of generated Custom Post Types (CPTs) The next step is … Read more

How to add a Custom Meta Box for more than one Post Type?

Whenever in doubt about a WordPress function, consult the Codex. http://codex.wordpress.org/Function_Reference/add_meta_box There, you’ll see that you need to add one meta box to each post type. add_action( ‘add_meta_boxes’, ‘myplugin_add_custom_box’ ); function myplugin_add_custom_box() { add_meta_box( ‘myplugin_sectionid’, __( ‘My Post Section Title’, ‘myplugin_textdomain’ ), ‘myplugin_inner_custom_box’, ‘post’ ); add_meta_box( ‘myplugin_sectionid’, __( ‘My Post Section Title’, ‘myplugin_textdomain’ ), ‘myplugin_inner_custom_box’, … Read more

Custom Post Type Taxonomies -Posts not showing in Category or Tag pages

You were close with the code you posted in your comment. The issue is that you only tested for is_main_query, which will limit every query on your site to that single post type. function wpa82763_custom_type_in_categories( $query ) { if ( $query->is_main_query() && ( $query->is_category() || $query->is_tag() ) ) { $query->set( ‘post_type’, array( ‘post’, ‘resource’ ) … Read more

Displaying Multiple Post types in Taxonomy

Hook into pre_get_posts, check for the taxonomy, and set all four post types as the post_type parameter of the query object. Check out the Type Parameters section on the WP_Query docs for more information. <?php add_action(‘pre_get_posts’, ‘wpse87225_set_post_types’); function wpse87225_set_post_types($query) { if (is_admin() || !$query->is_main_query() || !is_tax(‘destination’)) { return; // bail, not where we want to … Read more

apply filters only to specific post listing without check the url parameters

Yes, you’re right. There is a clever way. post_row_actions filter can accept also second param $post from which you can get it’s post_type. See the code: add_filter( ‘post_row_actions’, array( $this, ‘remove_row_actions’ ), 10, 2); public function remove_row_actions( $action, $post ) { if ( ‘slider’ === get_post_type( $post ) ) { unset $action[‘view’]; return $action; } … Read more