简体   繁体   中英

Wordpress display private and public posts on Blog Page

Is there away in Wordpress to display both my private and public posts on the blog page.

I am also looking for a way on the single post page if it is private displaying a message indicating it is.

So is there away to display both private and public posts on my blog page and is there a if condition for if private post?

Yes, you can add this into query let say wp_query where you use for getting all post, in template or function anywhere.

just you can put below query into your template.

$args = array(
    'post_type' => 'blog',
    'post_status' => array( 'publish', 'private')
);
$query = new WP_Query( $args );

just put this into your template and you cat get all your private and publish post into template.

You can get your 'private' and 'public' posts in this way

$args = array(
    'post_status' => array( 'publish', 'private')
);
$query = new WP_Query( $args );

And then you can use get_post_status() inside the loop to get the status and indicate the message.

For your reference: https://developer.wordpress.org/reference/classes/wp_query/ https://developer.wordpress.org/reference/functions/get_post_status/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM