[Resolved] Restrict shown posts to logged in author…

Please login to receive premium support.

Support for the free plugin can be found here.

Home Forums Pro Support Restrict shown posts to logged in author…

Tagged: 

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #31020
    J
    Participant

    Hi there,

    Suppose I want to restrict the list generated by wpsp to posts of the logged-in author, what filter settings will then work?

    I tried:

    add_filter( 'wpsp_settings', function($settings){
        if(449 == (int) $settings['list_id']){
            $settings['author_id'] = get_the_author_id();
            } 
        } 
        return $settings; 
      });

    But that didn’t work.

    Thanks for any suggestion.

    J

    (BTW: where can I find the list of settings names?)

    #31025
    elvin
    Moderator

    Hi there,

    You’ll have to change the wp_query args to assign the current logged in user’s ID. To get the current user’s ID, use https://developer.wordpress.org/reference/functions/get_current_user_id/

    You then filter the query args of the plugin. You either use wp_show_posts_shortcode_args filter, or not use shortcode and use wpsp_display(wpsp_id_here, $args) function.

    The wpsp free version’s code is open to public. See the settings list here – https://github.com/tomusborne/wp-show-posts/blob/35e410d7800273fc66f211c0f80d553e95d17f83/wp-show-posts.php#L96

    #31027
    J
    Participant

    Hi,

    Works!

    add_filter( 'wp_show_posts_shortcode_args', function( $args, $settings ) {
        if(123 === (int)$settings['list_id']){
           $user_id = get_current_user_id();
           $args['author'] = $user_id;
         }
         return $args;
    }, 15, 2 );

    Thanks for your help!

    J

    • This reply was modified 3 months, 1 week ago by J.
    #31031
    elvin
    Moderator

    Nice one! No problem. Glad to be of any help. 😀

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.