Site logo

Archived topic

Custom Posts Not Showing on Author´s Page

13 replies · Started by Edmond on February 15, 2021

Viewing posts 1–14 of 14

Hello,

When I create a custom post, it doesn´t appear on the author´s page, even though my custom post type has support for authors. Could you help me fix this?

Thanks,
Edmond

Hi Edmond,

I don't think this issue is due to the theme.

Can you activate a twenty series WP theme to see if the same issue occurs there as well?

Hi Leo,

Thanks for your reply.

I´ve tried it with that theme, and the issue persists. I just wrote hoping you could give me a solution to fix it.

I added this code to function.php to fix it, however after it all the featured images on the author pages get big:

/* add_post_types_to_archives*/
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_author() && empty( $query->query_vars['suppress_filters'] ) ) {
$cptui_post_types = cptui_get_post_type_slugs();

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

Maybe you could help me with this please?

Thanks,
Edmond

Hi there,

Can you try doing a var_dump($cptui_post_types) to see if it returns any value? Let us know.

Hi Elvin,

I don´t know how to do this, as I´m not that good at coding. Could you tell me where this code goes?

Thanks,
Edmond

Hi,

We use var_dump() on variables to check if it is actually giving out the output we need.

Example PHP snippet:

add_action( 'wp_body_open', function() {
	$cptui_post_types = cptui_get_post_type_slugs();
    var_dump($cptui_post_types);
} );

This may print out your cpt post slugs or "NULL" on the top most part of your page. That's what we're trying to check to see if it works.

Hi Elvin,

I added the code you sent in functions.php and as a result got this on top of the page:

array(2) { [0]=> string(7) "product" [1]=> string(13) "hair_products" }

Thanks,
Edmond

Thank you.

That's good. That means its working as intended.

Can you try this PHP snippet instead?

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

    if ( $query->is_author() ) {
		$cptui_post_types = cptui_get_post_type_slugs();
		$query->set(
			'post_type',
			array_merge(
				array( 'post' ), // May also want to add the "page" post type.
				$cptui_post_types
			)
		);
	}
}
add_filter( 'pre_get_posts', 'my_cptui_add_post_types_to_archives' );

Let us know how it goes.

Hi Elvin,

I used the code you sent and it didn´t work.

Then I went to the layout settings, and added the width and height of the featured images there, and the images started showing in the right size, however, when I add the number of the columns, this doesn´t work. The featured images appear one on every row.

Before, in the same section of settings, I had the archive image layout set to full and the number of columns to 3. It used to work perfectly, but on custom post types it stopped appearing the same way.

So, now I need to figure out how to make the posts appear in 3 columns instead of one aligned to the center.

It seems like its working as it looks like it includes posts with non default post templates (makeup_products) etc.

Can you provide a list of the custom posts on your site? To check and verify if the snippet is working.

As for the column, it seems like the columns don't work if there's a custom post type in a list.

When checking author Maya's post archive, when the post list page has a makeup_products post type, it seems to break the columns, but when you check the next post list pages, you'll see that the posts are in 3 columns.

That said, can you try adding this PHP snippets out?

add_filter( 'generate_blog_columns','tu_portfolio_columns' );
function tu_portfolio_columns( $columns ) {
$cptui_post_types = cptui_get_post_type_slugs();
    if ( is_author() || is_post_type_archive( $cptui_post_types ) ) {
        return true;
    }

    return $columns;
}

add_filter( 'generate_blog_get_column_count','tu_search_column_count' );
function tu_search_column_count( $count ) {
$cptui_post_types = cptui_get_post_type_slugs();
    if ( is_author() || is_post_type_archive( $cptui_post_types ) ) {
        return 33;
    }

    return $count;
}

Let us know how it goes.

Hi Elvin,

Yes, you are right, my custom post page is only the makeup_products page. And I´ve tried adding the code you sent, but it gives a syntax error.

Thanks,

Edmond

That's quite strange. I've tested the code prior to posting it and it works on my end as shown in this demo of an author with CPT UI post - DEMO

You can see that there's a custom post titled CPT UI post and the posts are actually in columns.

Perhaps you missed some parts of the code when you copied? Any chance you could recheck? Let us know.

Thank you so much, this has been resolved. Like you said, I wasn't copying the code correctly, and it really worked.

Nice one. Glad you got it sorted. :D

This archived topic is closed to new replies.