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 starting with given letter?
- wp_pagenavi() with custom wp_query()?
- Custom Comment Types
- 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
- 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
- Show all custom post type posts sorted by custom taxonomy then by another custom taxonomy
- Group search results by post type, but hide post types with no results
- 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
- Pagination with custom post types results in 404 issues
- How do you output custom code between posts in the loop?
- How do I Use Nested Loops of Custom Post Types for MultiSite Blogs using WP_Query()
- Disable comments from showing up public for Custom Post Type
- Impossible to get Attachments Outside WordPress?
- List posts AND custom post type by category
- Custom Post Type loops and Disqus
- Help Structuring Query for Archive Pages
- Loop on front-page.php
- wp_query to find posts by year and month
- Loop of custom post type names
- Custom Post Type Taxonomies -Posts not showing in Category or Tag pages
- get_template_part for each level of taxonomy term
- Query custom post type in the loop
- Very Slow Page – How to Optimize # of Queries?
- WordPress Genesis custom taxonomy archive shows 3 repeats of each post
- Am unable to reset a query properly
- How do i calculate the total of values of custom fields in custom post types?
- Custom post type not displaying content from single-{custom post type} page
- Display all taxonomy terms, add class if term applies to current post
- A to Z List of Custom Post Type in three columns
- WP Query with categories only shows one post and ignores the category
- Add custom field in comments form
- Post ID randomly printing on page
- How do I know the ‘meta_key’ for ordering my custom post type
- Convert comments to Custom Post Type
- Only show posts with date of today or in the future (i.e don’t show past posts)?
- Sort posts in loop by the WooCommerce Membership of the author
- How to include custom post type posts on a page?
- 4 column-loop ordered alphabetically with entries grouped (and labeled) by their first letter
- Pagination Error : Duplicate argument being outputted
- Custom post type showing same Post on all Pages
- get comments by current user inside page template
- get parent content inside child posts
- WP_Query with custom post type ID
- Get data from PHP to JavaScript to set position of each post on front page
- display posts of custom post type with custom taxonomy
- assign different templates to custom post type with homepage loop
- Custom Post Type and Taxonomy Loop Output Is Wrong
- foreach loop inside the loop creating duplicates in output
- How to fetch posts that are stored in the different table than (default) wp_posts?
- Cant’ Display Custom Post Type Title Base on Tax Terms
- CPT archive page – show one post from each taxonomy term
- How do i display post from a taxonomy term?
- Custom loop request based on custom field
- If/Else child list for Custom Post Type single template within loop?
- Insert a Custom Post type into my Loop
- Custom Post Types Not Showing Up In query_posts Result
- Do I need a loop to display an object that attached to posts?
- “Order” doesn’t work in custom loop?
- How to change the comments form title based on post type
- Shortcode with loop stacks output
- Show custom post type event if current day using ACF
- How to create an IF statement in the Main Loop for Custom Post Types
- Custom meta fields not showing up in WP_Response Object via custom endpoint
- How to output and alert message when updating a post
- Display all posts from specific category and CPT
- Wrapping an unknown amount of posts inside separate HTML Containers during WP_Query loop
- sorting in wp query based on custom field value
- Custom post type loop without children
- How to display user-defined / custom post in wordpress?
- WordPress loop add heading before first of type
- Fetch loop of custom post types with AJAX
- Only show current category post
- Looping through custom taxonomy in one template
- get_post_meta for Custom Post Type ( CPT )
- How to keep a CPT stick to specific position?
- Is it possible to add query parameters on the archive page?
- Custom Loop Event Page
- Custom post type archive pagination with HTML5Blank theme?
- WordPress loop for multiple custom post types
- Pagination not working with custom loop
- Fallback if statement based on the number filtered from it
- Create custom post order (with custom post type meta)
- Pagination not working with custom loop
- Noob Loop Question
- Custom Post Types and 404 Pages
- the_content() stop images being pulled through
- Render a loop in Timber (twig for WordPress)
- show custom post’s post in two different divs [duplicate]
- Limit wordpress posts loop to continue onto another page
- Filter page ID outside the loop and order
- How can I show posts with the same tag?
- WordPress post objects in one parent post object