Skip Navigation

[Resolved] List of posts commented by current user

This support ticket is created 7 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Tagged: 

This topic contains 5 replies, has 2 voices.

Last updated by FedericoI4663 7 years, 7 months ago.

Assisted by: Shane.

Author
Posts
#437564

I have already created a view to display only posts created by the current user but now i need to create a view to display all users posts containing current user comments.

The idea is to have a collection of posts related somehow to the current user.

I was wondering if there is a way to use filtered views but i dont see how yet....

Could you please help?

Many thanks

#437684

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Federico,

Thank you for contacting our support forum.

I'm assuming that the comments that are being displayed are all the comments for the post.

To clamp down to a specific comment to a specific user you will need to create a custom shortcode in order to do this.

What I can do for you is to point you in the right direction in order to create this custom shortcode.

The function that you will need to use is this https://codex.wordpress.org/Function_Reference/get_comments

Please let me know if this helps.
Thanks,
Shane

#437922

Hi Shane,

In fact i need a page/view with two list:
- 1) all current user posts
- 2) all posts commented by the current user

For the 1) , no problem I got it using a filtered views.

For the second actually i wrote a shortcode that returns a comma separated string containing all id of posts having current user comments. (see code at the bottom)

But it seems that i can't use this IDs string (or array) in a conditional output, i would need an operator as SQL 'in'... can you suggest any method?

If you confirm that there is no ways to filter with Views i will end up to build the first list in Views and the second entirely generated by the shortcode, that would be a pitty.

Many thanks,
Federico

function get_posts_usr_commented() {

if ( is_user_logged_in()) {
        global $current_user;
        get_currentuserinfo();

$args = array(
    'post_type'      => 'any',
    'posts_per_page' => 5,
    'post__in' => array_unique( 
         wp_list_pluck( 
            get_comments( array(
                'user_id' => get_current_user_id() 
                )
            ),       
            'comment_post_ID' 
         )
    ),
);

$my_query = null;
$my_query = new WP_Query( $args );
if( $my_query->have_posts() ) {
        $postinfo =  'Post Id(s):  ';
             while ($my_query->have_posts()) : $my_query->the_post(); 
                  $postinfo .= implode (" ," ,array( 'post_id' => get_the_ID() )).","; 
             endwhile;       
        }
        
       return $postinfo;
        wp_reset_query();  // Restore global post data stomped by the_post().
        }
}
add_shortcode( 'get_currentusr_interest', 'get_posts_usr_commented' );
#438214

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Federico,

This will require some custom code. You are able to display posts only for the current user but for comments you will need to do some custom shortcode for this.

This is because our views plugin doesn't have a shortcode to display the post comments.

Thanks,
Shane

#438244

Hi Shane,

i will use some custom code; but still i need your advice.
Coding to get my list of posts i need a Toolset custom type field wpcf-categoria (Category).
When i query for the post category i get an integer and not the name.

Could you please tell me how can i get the category name or where is stored in the DB?

My code:
[php]
// get Categoria
$custom_fields = get_post_custom($pid);
$my_custom_field = $custom_fields['wpcf-categoria'];
foreach ( $my_custom_field as $key => $value ) {
$t .= $key . " => " . $value . "<br />";

// $value in a number, not the category name

}
[php]

Thanks,
Federico

#438368

Never mind , i solved with:

types_render_field("categoria", array("raw"=>"false"))
 
This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.