How to display Custom posts Type on a WordPress Tag Archive Page

How to display Custom posts Type on a WordPress Tag Archive Page

 

How to display on a WordPress tag page

If your WordPress tag page isn’t showing post, pages or custom post types, it might be because WordPress, by default, only shows posts from the standard “post” type on tag archive pages. To display custom post types on tag archive pages, you’ll need to modify your theme’s functions.php file or create a custom plugin.

 

Here’s how you can fix it:

Step 1: Modify the Query to Include Custom Post Types

You can hook into WordPress’ pre_get_posts action to modify the query for the tag pages to include your custom post types. Add the following code to your functions.php file:

 

function include_custom_post_types_in_tag_archive($query) {
if ( $query->is_tag() && $query->is_main_query() && !is_admin() ) {
// Add your custom post types
$query->set( ‘post_type’, array( ‘post’, ‘your_custom_post_type’ ) );
}
}
add_action( ‘pre_get_posts’, ‘include_custom_post_types_in_tag_archive’ );

 

Step 2: Flush Rewrite Rules

After adding this code, flush your permalinks by going to Settings > Permalinks in the WordPress admin and simply click “Save Changes.”

Step 3: Check Your Custom Post Type Registration

When you registered your custom post type, ensure that it supports tags. In your register_post_type() function, make sure you’ve included 'taxonomies' => array('post_tag') in the arguments.

 

Step 4: Test Your Tag Archive

Visit one of your tag archive pages and see if the custom post type posts are showing up.

Let me know if you need further assistance or have additional questions!

3 Comments

  1. Aute mi ut suspendisse velit leo, vel risus ac. Amet dui dignissim fermentum malesuada auctor volutpat, vestibulum ipsum nulla.

    • Sed reprehenderit quam, non felis, erat cum a, gravida lorem a. Ultricies in pellentesque ipsum arcu ipsum ridiculus velit magna, ut a elit est. Ultricies metus arcu sed massa. Massa suspendisse lorem turpis ac.

  2. Massa suspendisse lorem turpis ac. Pellentesque volutpat faucibus pellentesque velit in, leo odio molestie, magnis vitae condimentum.

Leave a Reply

Your email address will not be published. Required fields are marked *