[Resolved] Hook doesn’t work on CPT category archive

Home Forums Support [Resolved] Hook doesn’t work on CPT category archive

Home Forums Support Hook doesn’t work on CPT category archive

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
  • #1574031


    I have custom post type with some ACF. I would like to display this ACF under the title of CPT in Archive of this CPT and in the Category of this CPT. In Archive it works perfectly, but in category this hook is missing.
    I add the these rules for location:
    – CPT Category – ‘name of the category’
    – CPT Archive
    – CPT Category Archive – ‘name of the category’
    I use the hook called ‘generate_after_entry_title’

    At first time I tried to create my own files for this CPT: archive-nameofcpt.php and content-nameofcpt.php, but the hook disappeared from Archive too, so I deleted it. Should I create some special files for category or something else?

    I work on localhost for this time, but I try to upload it on some webhosting if you need to see it.

    Thank you


    And second thing is, that If I want to test it, and I pick the location of the hook as:

    Post Category Archive – all categories

    and press Update, this setting is automatically changed to CPT Category Archive and nothing is displayed. πŸ™


    Well, I found the cause of the problem. I use this filter in functions.php for displaying the CPT (named pedagog) in categories. If I delete it, the hook works in categories for Posts. But categories dont display the CPT. How to display the CPT in categories with working hooks, um..?

    add_filter('pre_get_posts', 'query_post_type');
    function query_post_type($query) {
      if( is_category() ) {
        $post_type = get_query_var('post_type');
            $post_type = $post_type;
            $post_type = array('nav_menu_item', 'post', 'pedagog'); 
        return $query;
    Lead Developer
    Lead Developer

    Hi there,

    What exactly is that filter trying to do? May be able to offer an alternative.

    Let me know πŸ™‚


    Hello Tom,
    thank you for your reply. I searched how to rebuild the code of the filter above. I try this and now the hooks work πŸ™‚

    function custom_post_type_cat_filter($query) {
    	if ( !is_admin() && $query->is_main_query() ) {
    	  if ($query->is_category()) {
    		$query->set( 'post_type', array( 'post', 'pedagog' ) );

    It displays the custom post types called ‘pedagog’ in category archive. Without this code I can add category to the CPT, but nothing is displayed on category archive. I am sorry for the interruption πŸ™‚

    Lead Developer
    Lead Developer

    Awesome, all working correctly now? πŸ™‚

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.