Editing template files for CPT

Hi, i’m trying to edit the template files for my custom post types but when i edit the file content-cptname.php nothing happens, i can only edit the content.php file on my child-theme. Same on archive-cptname.php, i can only edit directly on archive.php

other problem is on the functions, i use sparkling on my site and now changing to activello, in sparkling i use this function to filter and show only the cpt from certain category and with ‘publish’ status, but this same functions don’t work on activello, i can filter by category but not by post_status.

add_action( 'pre_get_posts', 'add_grupo_to_query' );

function add_grupo_to_query( $query ) {
  if ( is_home() && $query->is_main_query() )
    $query->set( 'post_type', array( 'post_type' => 'grupo', 'post_status' => 'publish',));
  return $query;
}

function my_home_category( $query ) {
 if ( $query->is_home() && $query->is_main_query() ) {
 $query->set( 'cat', '205');
 }
}
add_action( 'pre_get_posts', 'my_home_category' );

thanks

Hi @thiagosartorelli,

I hope you are well today and thanks for posting here.

There isn’t any template file content-cptname.php in the WordPress so it won’t work. Find more information about it on the following page.

but this same functions don’t work on activello, i can filter by category but not by post_status.

It seems your shared code is wrong and it should be as following.

add_action( 'pre_get_posts', 'add_grupo_to_query' );

function add_grupo_to_query( $query ) {
  if ( $query->is_home() && $query->is_main_query() ){
    $query->set( 'post_type', 'grupo');
    $query->set( 'post_status', 'Publish');
    $query->set( 'cat', '205');
  }
  return $query;
}

Best Regards,
Movin

Thank you for your response.

About the function, doesn’t work but i will learn more and if needed i’ll open another topic for this specific subject.

Lets talk about custom post types, you are right content-$posttype.php isn’t on the documentation and this is a strange way to archive that, but works fine on the theme that i’m using (sparkling-child). Then i noticed that i changed the <?php get_template_part( ‘content’, get_post_format() ); ?> on archive.php to <?php get_template_part( ‘content’, get_post_type() ); ?> and that is why i can do this on sparkling-child. Now i did the same on activello-child and works.

I need this functionality because i have 4 different post types who has to be shown in specific ways with different taxonomies and custom fields.

Another way to do this should be writing “ifs” on archive.php for each case and setting this variations on content.php.

Thank you for your time.

Awesome great to see you got that resolved.

Please advise if you have more questions.

Have a fantastic day!