Site logo

Archived topic

Layout related query

19 replies · Started by Ajay on January 10, 2023

Viewing posts 16–20 of 20

I would suggest you follow some tutorials or get a developer, as this is custom development, and its not something we can teach or do for you.

I can only assist a little:

1. in that document, there is this code:

function my_cptui_add_post_types_to_archives( $query ) {
	// We do not want unintended consequences.
	if ( is_admin() || ! $query->is_main_query() ) {
		return;    
	}

	if ( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) {

		// Replace these slugs with the post types you want to include.
		$cptui_post_types = array( 'my_post_type', 'my_other_post_type' );

		$query->set(
	  		'post_type',
			array_merge(
				array( 'post' ),
				$cptui_post_types
			)
		);
	}
}
add_filter( 'pre_get_posts', 'my_cptui_add_post_types_to_archives' );

Add the code to your site, this doc explains how:

https://docs.generatepress.com/article/adding-php/

2.

in that code you will see this line:

$cptui_post_types = array( 'my_post_type', 'my_other_post_type' );

where it says my_post_type and my_other_post_type change them to the slugs of your CPTs.

i am using genratblocks pro can i achieve through that?

If you want post archives to include your CPTs you have to use the code above.
GenerateBlocks won't do that.

Thanku so soo much code is working. You guys are amazing

Super happy to hear that. You're welcome

This archived topic is closed to new replies.