• Resolved DarrenMooney

    (@darrenmooney)


    Sorry to bother you folks with this, but I’m at the hair pulling stage and need some fresh thinking.

    Creating CTP, nothing major. However I’m unable to display the CPTs on the Author archive. I have done this before, and have Googled for hours, trying to find something I’m not seeing, without any look.

    I have been able to get the CPTs to display on archives with

    function add_custom_post_type_to_query( $query ) {
    	if ( $query->is_home() && $query->is_main_query() ) {
    		$query->set( 'post_type', array('news', 'videos', 'screenshots', 'events') );
    	}
    }
    add_action( 'pre_get_posts', 'add_custom_post_type_to_query' );

    And thought I would be able to do the same for author pages with:

    function post_types_author_archives($query) {
    	if ( $query->is_author() )
    		$query->set( 'post_type', array('screenshots', 'videos', 'events', 'news') );
    	remove_action( 'pre_get_posts', 'post_types_author_archives' );
    }
    add_action( 'pre_get_posts', 'post_types_author_archives' );

    But for some reason it just won’t display the posts.

    I have a feeling I’m missing something, or doing something wrong. But I just can’t see it.

    For reference, here is how one of the CPTs is registered:

    function cpt_register_news() {
    	$labels = array(
    		"name" => __( 'News', '' ),
    		"singular_name" => __( 'News', '' )
    	);
    	$args = array(
    		"label" => __( 'News', '' ),
    		"labels" => $labels,
    		"description" => "",
    		"public" => true,
    		"publicly_queryable" => true,
    		"show_ui" => true,
    		"show_in_rest" => false,
    		"rest_base" => "",
    		"has_archive" => true,
    		"show_in_menu" => true,
    		"exclude_from_search" => false,
    		"capability_type" => "post",
    		"map_meta_cap" => true,
    		"hierarchical" => false,
    		"rewrite" => array( "slug" => "news", "with_front" => true ),
    		"query_var" => true,
    		'menu_icon' => 'dashicons-media-document'
    	);
    	$supports = array(
    		"title",
    		"editor",
    		"thumbnail",
    		"custom-fields",
    		"comments"
    	);
    	register_post_type( "news", $args );
    }
    add_action( 'init', 'cpt_register_news' );

    Thanks for any help or insights in advance.

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

    (@darrenmooney)

    Forgot to add above. I could of course do a work around, and just specifically query the CPTs on the Author page. It works, cool. But this problem is really annoying me now and I would love to destroy it… forever and ever and ever.

    Thread Starter DarrenMooney

    (@darrenmooney)

    Right, so it was the function to include CTPs in archives that apparently prevented it for author archives.

    Removing the first function above fixed it.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘CTP Author Page’ is closed to new replies.