[wp-trac] [WordPress Trac] #45394: get_posts fails to return results when accessing admin with a custom user role

WordPress Trac noreply at wordpress.org
Wed Nov 21 17:35:55 UTC 2018


#45394: get_posts fails to return results when accessing admin with a custom user
role
--------------------------+-----------------------------
 Reporter:  tonydjukic    |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Query         |    Version:  4.9.8
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 Not sure if this is intentional or not, or if there are some capabilities
 required for custom user roles for 'get_posts' to work, but I'm finding
 that using 'get_posts' in a CPT metabox works exactly as expected and
 returns the correct results when accessing the admin as an admin or
 editor, however, accessing the same screen as any number of custom user
 roles results in 'get_posts' not returning any data.

 There are no error messages and no indication anywhere online that
 get_posts() is somehow dependent on user role.

 To my best estimation this appears to be a bug - get_posts() would work on
 the front end without a user being logged in, so the user level/role on
 the back end shouldn't be relevant to whether or not results are returned.

 Here's an example:

 {{{#!php
 <select name="mwss_session">
         <option value="">Please select a Session</option>
         <?php
                 $get_sessions = get_posts( array(
                         'post_type'         => 'seasonal_sessions',
                         'post_status'       => 'publish',
                         'posts_per_page'    => -1,
                         'meta_key'          => 'mwss_session_status',
                         'meta_value'        => 'true',
                         'meta_compare'      => '='
                 ) );
                 $selected_session = $mwss_session;
                 foreach( $get_sessions as $active_session ) {
                         $session_name = get_the_title( $active_session->ID
 );
                         echo '<option value="' . $session_name . '"';
                         if( $selected_session === $session_name ){ echo
 'selected'; }
                         echo '>' . $session_name . '</option>';
                 }
         ?>
 </select>
 }}}

 To recap:
 - In wp-admin, logged in as Admin or editor, the dropdown is populated
 with results
 - On front end, logged in with custom user role (most basic level, almost
 equivalent to a subscriber), the dropdown is populated with results
 - in wp-admin, logged in as custom user role, (consistent with editor
 caps), the dropdown is empty

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/45394>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list