- This topic has 13 replies, 3 voices, and was last updated 3 years, 1 month ago by Elvin.
-
AuthorPosts
-
February 15, 2021 at 11:58 am #1659458Edmond
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,
EdmondFebruary 15, 2021 at 12:06 pm #1659478LeoStaffCustomer SupportHi 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?
February 15, 2021 at 12:15 pm #1659499EdmondHi 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,
EdmondFebruary 15, 2021 at 5:32 pm #1659685ElvinStaffCustomer SupportHi there,
Can you try doing a
var_dump($cptui_post_types)
to see if it returns any value? Let us know.February 16, 2021 at 1:09 am #1659938EdmondHi 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,
EdmondFebruary 16, 2021 at 1:26 am #1659950ElvinStaffCustomer SupportHi,
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.
February 16, 2021 at 4:18 am #1660071EdmondHi 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,
EdmondFebruary 16, 2021 at 6:12 pm #1661114ElvinStaffCustomer SupportThank 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.
February 16, 2021 at 11:40 pm #1661292EdmondHi 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.
February 17, 2021 at 6:02 pm #1662546ElvinStaffCustomer SupportIt 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.
February 18, 2021 at 1:47 pm #1663734EdmondHi 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
February 18, 2021 at 5:54 pm #1663896ElvinStaffCustomer SupportThat’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.
February 20, 2021 at 11:17 am #1665902EdmondThank you so much, this has been resolved. Like you said, I wasn’t copying the code correctly, and it really worked.
February 21, 2021 at 6:27 pm #1667088ElvinStaffCustomer SupportNice one. Glad you got it sorted. 😀
-
AuthorPosts
- You must be logged in to reply to this topic.