If we want to avoid any filters and manual SQL queries, we could try (untested):
$args = array(
'post_type' => 'foods',
'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 = new WP_Query( $args );
Related Posts:
- Display Authors Comments on Profile Page
- Pagination not working with custom loop
- Display all posts in a custom post type, grouped by a custom taxonomy
- Have different number of posts on first page
- Display all posts starting with given letter?
- How do you get the count of posts in an archive page?
- Why are the comments disabled by default on my custom_post_types?
- Why are comments and trackbacks still getting through for custom post types?
- group search results by post type?
- wp_pagenavi() with custom wp_query()?
- How to use a custom post type as front page?
- How to show Y number of custom posts after every X normal posts?
- Get Custom post with ID
- Custom Post Type Pagination Not Working On Archive Page
- Custom Post Type Archive Page: Set Posts Per Page, Paginate
- Display several random posts, but make sure a condition is met
- Custom Comment Types
- Category as Class for Custom Post Type
- Archive page…limiting posts per page
- Adding custom post type to loop
- modify all posts of a category to “no comments allowed”
- Custom comment status possible?
- feed links for custom post type pages
- how do I group content in magazine-style ‘issues’?
- WP_Query to loop a Custom Field, Custom Post Types do not show
- Retrieving 3 latest post from each of 5 different custom post types
- Seperating custom post type comments from regular blog posts comments
- How to query custom posts using a dynamic category
- WordPress “Loop” with large set of results
- Add comments meta fields to comments metabox on post edit screen
- Pagination go to first page if i’m on last post
- Grossly inefficient wordpress loops!
- Posts in Multiple Columns and Rows with one single loop
- Exclude post_type from admin comments_list
- Order custom posts by taxonomy?
- Newer/Older posts links display same posts on every page
- Best way to style first post differently?
- How to solve suspected memory issue in custom WordPress loop?
- List events by month
- WP_Query on custom post type not displaying, multiple loops & get_template_part
- Conditional two level dropdown filter for custom post type
- How do I write this SQL statement for Posts written in last 24 hours?
- Show all custom post type posts sorted by custom taxonomy then by another custom taxonomy
- Alphabetical sorting of custom post type – one letter per page
- List all posts in Custom Post Type but group dynamically by Custom Taxonomies
- Using new WP_Query in shortcode in a custom field causes the main post content to not display
- Taxonomy posts on Archive page
- Group search results by post type, but hide post types with no results
- Recent comments on author page?
- How to show posts from multiple post types in a single loop? And display them separately on the same template
- How to show related posts by category or custom post type?
- Fix custom query pagination without changing site-wide posts-per-page settings
- Custom post type loops with different page templates
- Randomly placed sticky custom posts complemented by blog posts
- How to create posts (not post template) to be displayed on projects page?
- Custom Post Loop in Archive returns same the_permalink
- WP_Query post at custom position
- wp_query and comment_parent – select only posts with top level comments
- How to display the rest of categories on Portfolio filterable
- changing default comment form arguments [duplicate]
- Should unaltered default loop/query return a list of custom posts belonging to a custom taxonomy?
- Comment moderation on custom post types
- 404 error PageNavi custom type taxonomy | wordpress
- WooCommerce – Show orders for a specific product ? [closed]
- Get_post_meta() won’t return value
- exclude custom post type by meta key in wp_query
- Automatically check “Allow comments” for custom post type [duplicate]
- Query for posts in 2 taxonomies
- Pagination with custom post types results in 404 issues
- Problems excluding a custom post-type from the loop
- Query Custom Post by Category
- How to get current post id of a custom post type in a loop using template singel-{custom type}.php?
- IF statement in a do_shortcode
- How do you output custom code between posts in the loop?
- Get the title of custom post type in another loop
- How to append element after thumbnail
- How do I Use Nested Loops of Custom Post Types for MultiSite Blogs using WP_Query()
- ‘category__and’ for custom taxonomy?
- WP_Query and using a variable for ‘cat’=> in the args array = WP Bug?
- How could I create a ‘private comments’ section on a custom post type?
- Disable comments from showing up public for Custom Post Type
- Separate Posts and Custom Post Type in Custom Taxonomy archive template
- Posts navigation in custom post type single.php not working
- Displaying custom posts only if custom meta box’s date is not expired
- Integrating Orbit slider into wordpress through custom post type
- Display custom post on home page based on a metabox selection
- Impossible to get Attachments Outside WordPress?
- List posts AND custom post type by category
- How to list custom post types?
- How to dynamically build a multiple taxonomy query loop within a post type’s single loop?
- Custom Post Type loops and Disqus
- Why does using WP_Query inside a shortcode in an elementor page cause the arguments for WP_Query to get malformed?
- Unable to get post content from custom post type loop
- Lists Posts from CPT that match the Title of the Page
- “Allow Comments” box cannot be checked
- Help Structuring Query for Archive Pages
- Display custom field of specific post where post title matches variable
- Custom Post Type not visible on category page
- get_template_part for custom post type content not working
- How would I create a shortcode to display a custom post within a page or regular post?