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....
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' );
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.
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?