0
function wbg_custom_attribute($pages, $parsed_args){
    global $wpdb;
    $user = wp_get_current_user();
    //print_r($output);
    
    //print_r($pages);
    if ( in_array( 'translator', (array) $user->roles ) && $parsed_args['post_type']=='books') {
        
        $post_status  = $parsed_args['post_status'];
        if ( 1 == count( $post_status ) ) {
            $where_post_type = $wpdb->prepare( 'post_type = %s AND post_status = %s', $parsed_args['post_type'], reset( $post_status ) );
        } else {
            $post_status     = implode( "', '", $post_status );
            $where_post_type = $wpdb->prepare( "post_type = %s AND post_status IN ('$post_status')", $parsed_args['post_type'] );
        }
        $join = " LEFT JOIN $wpdb->postmeta ON ( $wpdb->posts.ID = $wpdb->postmeta.post_id )";
 
        // meta_key and meta_value might be slashed.
        $meta_key   = wp_unslash( 'book_translator' );
        $meta_value = wp_unslash( get_current_user_id() );
        $where .= $wpdb->prepare( " AND $wpdb->postmeta.meta_key = %s", $meta_key );
        $where .= $wpdb->prepare( " AND $wpdb->postmeta.meta_value = %s", $meta_value );
        $query  = "SELECT * FROM $wpdb->posts $join WHERE ($where_post_type) $where ";
        $pages = $wpdb->get_results( $query );
        if ( empty( $pages ) ) {
            $pages = array();
        } else {
             $pages = array_map( 'get_post', $pages );
        }
        
    }
    //print_r($dropdown_args);
    return $pages;
}

If I logged in as a translator then I should not be able to see the "Book Categories" and I must select a book from "Select Book"

enter image description here

But The problem is if I logged in as a translator than I cannot see the "Select Book" option. enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.