Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter ivanchaquea

    (@ivanchaquea)

    update: ading these 2 conditions the backend and post page problems are fixed

    add_filter ('pre_get_posts', 'mostrar_testimonios' );
    function mostrar_testimonios( $query ) {
    	    if ( is_category() ||  !is_admin()  && $query->is_category_page )
    	        $query->set( 'post_type', array( 'post', 'testimonios' ) );
    	    return $query;
    	}

    but the wp_nav_menu keeps dissapearing on the target page ( categories in my case)

    Thread Starter ivanchaquea

    (@ivanchaquea)

    edit: im using the default workdpress categories i created one category with a sub category, added some entries to the main category and then added my custom post type to the sub category. then i needed to display those subcategory items on my page. this is the updated code:

    // create post type: testimonios
    add_action('init', 'post_type_testimonios');
    add_filter( 'pre_get_posts', 'mostrar_testimonios'  );
    
    function post_type_testimonios() {
    
        register_post_type(
            'testimonios',
            array(
                'label' => __('Testimonios'),
                'description' => __('Ingresa un testimonio de  pacientes.'),
                'public' => true,
                 'show_ui' => true,
                   'capability_type' => 'post',
                   'hierarchical' => false,
                   'rewrite' => true,
                   'query_var' => true,
                'menu_position' => 15,
                'supports' => array (
                    'title',
                    'editor',
                    'thumbnail',
                    'custom-fields',
                    'categories'),
                    'taxonomies' => array('post_tag','category')
            )
        );
     register_taxonomy_for_object_type('category', 'external');
     register_taxonomy_for_object_type('post_tag', 'external');
    
    }
    function mostrar_testimonios( $query ) {
            if ( is_category()  )
                $query->set( 'post_type', array( 'post', 'testimonios' )  );
            return $query;
        }

    and it works as expected, the custom post type ( testimonios) is displaying well on its sub category. but, when i navigate on any category page, the wp_nav_menu() fails to load. its printing the cointainer div and the uls but none of the link items.

    if i change or add any other page type to the line if ( is_category() ), like is_home(), or is_single() the menu will stop working on those too.

    im also getting this error while navigating the categories panel on the backend

    Warning: Illegal offset type in isset or empty in /home/public_html/wp/wp-includes/post.php on line 736

    wish dissapears when i comment these lines :

    add_filter( 'pre_get_posts', 'mostrar_testimonios'  );
    
    function mostrar_testimonios( $query ) {
             if ( is_category()  )
                 $query->set( 'post_type', array( 'post', 'testimonios' )  );
             return $query;
         }

    im not sure what other function could i use to add these posts to the loop without needing to set more queries into it, or would that be the only choice for it?

Viewing 2 replies - 1 through 2 (of 2 total)