• Resolved enricotv

    (@enricotv)


    Hello to all,
    it is possible to make the posts of the widget Post Grid/Slider/Carousel display only the posts of the current logged in user?
    I know I need a query like that

    $author_query = array(
       'posts_per_page' => '-1',
       'author' => $current_user->ID,
    );

    or

    add_action( '............, function( $query ) {
    	if ( is_user_logged_in() ){
    		$query->set( 'author', get_current_user_id() );
    	}
    } );

    but I don’t know how to proceed.
    Thank you

    • This topic was modified 2 years, 7 months ago by enricotv.
Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author WP Royal

    (@wproyal)

    Hi,
    Please search for

    $author = ! empty( $settings[ 'query_author' ] ) ? implode( ',', $settings[ 'query_author' ] ) : '';

    and add these code below it

    if ( is_user_logged_in() ){
        $logged_in_user = wp_get_current_user();
        $author = $logged_in_user->ID;
    }

    Kind Regards,
    Nick`

    • This reply was modified 2 years, 7 months ago by WP Royal.
    Thread Starter enricotv

    (@enricotv)

    Thank you Nick
    for your reply, but where should I go to look for this code?
    On functions.php or in a template page? if I add it to functions.php it will take effect on every page of the site

    • This reply was modified 2 years, 7 months ago by enricotv.
    Thread Starter enricotv

    (@enricotv)

    I found it on wpr-grid.php of the royal plugin, but I think entering that code will affect every widget on the site, I’m doing it wrong?

    Thread Starter enricotv

    (@enricotv)

    I added the code above but I actually only see the posts of the current user while I need those of the site admin to show as well

    Plugin Contributor George

    (@rubeushagrid13)

    Hi again,

    If you didn’t change the ID of administrator u can use

    
    if ( is_user_logged_in() ){
       $logged_in_user = wp_get_current_user();
       $author = '1' . ',' . $logged_in_user->ID;
    }

    If it doesn’t work contact us again please,
    Kind regards

    • This reply was modified 2 years, 7 months ago by George.
    Thread Starter enricotv

    (@enricotv)

    Thank you @rubeushagrid13,
    unfortunately it does not work because the widget is present in several pages visible both by logged in and not with different types of posts and categories.
    I think the best strategy is to go and modify the code under the ‘options’ in order to have the choice “Current logged in user” as well as the names of the users.

    $this->add_control(
    			'query_author',
    			[
    				'label' => esc_html__( 'Authors', 'wpr-addons' ),
    				'type' => Controls_Manager::SELECT2,
    				'multiple' => true,
    				'label_block' => true,
    				'options' => Utilities::get_users(), 
    				'separator' => 'before',
    				'condition' => [
    					'query_source!' => [ 'current', 'related' ],
    					'query_selection' => 'dynamic',
    				],
    			]
    		);

    Kind regards

    • This reply was modified 2 years, 7 months ago by enricotv.
    • This reply was modified 2 years, 7 months ago by enricotv.
    • This reply was modified 2 years, 7 months ago by enricotv.
    • This reply was modified 2 years, 7 months ago by enricotv.
    Thread Starter enricotv

    (@enricotv)

    Another idea would be to duplicate the widget and leave one unchanged and make the change to the wpr-grid.php to the other.
    Kind regards

    • This reply was modified 2 years, 7 months ago by enricotv.
Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Post of current logged in user in Post Grid/Slider/Carousel’ is closed to new replies.