php - Stop WordPress from filtering out draft posts for guests in get_posts -


i have page on wordpress site uses template , in template, have used get_posts fetch results cpt. in cpt, 1 post allowed have publish status @ time whilst others stay in draft mode. however, want guest users (i.e. site visitors don't have access account on site) able visit page , see posts in draft state.

i'm using these args fetch results

$args = array(               'name' => $slug,               'post_type' => 'catalog',               'post_status' => array('draft', 'publish'),               ); $catalogs = get_posts($args); 

the code above works fine signed in users returns empty when sign out. i'm sure wordpress filter responsible this. can't figure out how make stop.

additional info: can use $wpdb fetch desired results i'm hoping can done custom filter. did research couldn't find useful , wordpress codex doesn't contain information regarding this.

ok, think mean. try below snippets

/*  * on drafts should visible.  */ function show_drafts( $query ) {     $query->set( 'post_status', array( 'publish', 'draft' ) ); }  add_action( 'pre_get_posts', 'show_drafts' ); 

this should allow both draft , publish appear visible when use get_posts method.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -