• Resolved Arsalan

    (@sam3000us)


    Hello,

    I’m using (user custom field – multiselect checkbox) to display the users of specific role (e.g. EDITORS)
    and I want to display them all in the frontend like this:

    Chosen members: (the users that I chose when I created the post)
    Excluded members: (the users that I did NOT choose when I created the post)

    I don’t want to duplicate the custom field, I want a way to use only one user custom field to display both (chosen and unchosen users)

    Thanks.

Viewing 1 replies (of 1 total)
  • Plugin Support Paul Clark

    (@pdclark)

    Formatted as a plugin which adds a shortcode, [editors-and-not-editors]:

    <?php
    /*
     * Plugin Name: Editors & Not Editors Shortcode
     * Description: Shortcode <code>[editors-and-not-editors]</code>.
     */
    
    add_shortcode(
    	'editors-and-not-editors',
    	function(){
    		ob_start();
    		
    		$selected_users = (array) get_post_meta( get_the_ID(), 'editors', false ); // Field name: "editors"
    
    		$not_selected_users = get_users([
    			'role__in' => [ 'administrator', 'editor', 'author', 'contributor', 'subscriber' ], // Remove roles as preferred
    			'exclude' => wp_list_pluck( $selected_users, 'ID' ),
    		]);
    
    		echo '<p>Chosen Members: ';
    		echo implode( ', ', wp_list_pluck( $selected_users, 'display_name' ) );
    		echo '</p>';
    		echo '<p>Excluded Members: ';
    		echo implode( ', ', wp_list_pluck( $not_selected_users, 'display_name' ) );
    		echo '</p>';
    
    		return ob_get_clean();
    	}
    );
Viewing 1 replies (of 1 total)
  • The topic ‘Display chosen and unchosen users’ is closed to new replies.