Support Forum
Support › MB Frontend Submission › All Post Types on Account Page
For some reason on the author account pages, posts from some post types are not being displayed.
I have post types A, B, C, D, E & F.
If I query like this:
$args_published = array(
'author' => $user_id,
'posts_per_page' => -1,
'post_type' => array('A','B','C','D','E','F'),
'post_status' => 'publish',
'orderby' => array('date'=>'ASC','title'=>'ASC')
);
all of the published post from post types A, B, C & D by the current author are displayed, but not from post types E or F. I've tried putting all of the post types in an array, but that doesn't change anything.
These two post types were not created differently than any of the others, in fact I duplicated and renamed a couple of post types that do show up, moves a few posts into them and they still don't show up.
If I query like this:
$args_published = array(
'posts_per_page' => -1,
'post_type' => array('A','B','C','D','E','F'),
'post_status' => 'publish',
'orderby' => array('date'=>'ASC','title'=>'ASC')
);
it shows all of the published posts from all of the post types no matter who the author is, which is to be expected and fine for admins who need to see everyone's posts, but isn't good if you only want the author to see their own posts.
This is really frustrating to me as I want my authors and contributors to be able to see all of their posts from all of the post types.
Am I doing something wrong in the query? Is there another way to query so that I can show all posts from all post types by individual author?
Hi Becky,
You can use the parameter author
to show posts of an author. Read more here https://developer.wordpress.org/reference/classes/wp_query/#author-parameters
and it is possible the number of posts displayed is limited, you can assign the parameter posts_per_page
to -1
to display all posts. Read more here
https://developer.wordpress.org/reference/classes/wp_query/#post-page-parameters
I am doing both of those things, as you can see in the code.
Hi,
So if you query for only two post types E, F, does that display posts of them? It is possible that the current user is not the author of posts from two post types E, F.
On the admin account, my post table show's the post title, type of post, author, status and date added.
This is the query for that page:
$args_published = array(
'posts_per_page' => -1,
'post_type' => 'any',
'post_status' => 'publish',
'orderby' => array('date'=>'ASC','title'=>'ASC')
);
It shows all post types as well as pages, which is exactly what it should do. Notice that I did not include the author parameter in the query.
If I add the author parameter to the query, it makes no difference what I do with the post_type parameter, posts from post types A, B, C, & D will be displayed. I can query for only post_type E or for post_type gallery or for post_type page or for post_type A and posts from post types A, B, C & D will be displayed.
It seems like the author parameter nullifies the post_type parameter.
Hi,
Please create a staging site and share the site credentials, and some screenshots via this contact form https://metabox.io/contact/. I will help you to check the issue.