I recently needed the same thing, I had menu of categories and I needed to get the categories that in the menu. After a several hours digging in the WP core, I found the
wp_get_nav_menu_items() function that helped me.
I finnally came with this, 220 was my menu_id
$navcat = wp_get_nav_menu_items('220');
foreach ($navcat as $obj) {
$catid = $obj->object_id;
$category = get_category($catid);
...
...
}
So, if you have a nav menu of posts, I assume you can do the same, something like this should work –
$nav_items = wp_get_nav_menu_items('220');
foreach ($nav_items as $obj) {
$objid = $obj->object_id;
$postobj = get_post($objid);
//do stuff with the post..
}
I think it can save you some complexed mySQL query…
Related Posts:
- Slow SQL_CALC_FOUND_ROWS Query
- Order by custom table and multiplication
- why update and delete query not worked in custom table?
- How to implement a new row_count method in WordPress?
- how to get Nearby zipcode
- WP_Query with page_ids in arguments without a result
- Why last row deleted when refresh page
- Fix wp_term_relationships slow query in get_posts
- Sorting query_posts() with a complex orderby filter
- WP_Query always returning the last custom post
- Custom query_posts() parameter
- SQL query into to WP query
- When should you use WP_Query vs query_posts() vs get_posts()?
- When to use WP_query(), query_posts() and pre_get_posts
- Get post ids from WP_Query?
- Nested meta_query with multiple relation keys
- Some doubts about how the main query and the custom query works in this custom theme?
- Wp get all the sub pages of the parent using wp query
- Ignoring initial articles (like ‘a’, ‘an’ or ‘the’) when sorting queries?
- Return only Count from a wp_query request?
- Use REGEXP in WP_Query meta_query key
- How to query for most viewed posts and show top 5
- WP Query where title begins with a specific letter
- WP_Query vs get_posts
- Order by DESC, ASC in custom WP_Query
- How to prevent execution of default query, while preserving ability to use WP_Query in template?
- Using OR conditions in meta_query for query_posts argument
- Query Posts in a Predefined Order
- Order posts by ID in the given order
- Should I use Transients with W3 Total Cache APC Caching? [closed]
- Add indexing to meta_value in wp_postmeta
- Getting wrong relationship value in $args in wp_Query?
- find a random blogid across my multisite network that has at least one post published
- Query Multiple Post types each with own meta query
- Get the number of posts from the current page results
- WordPress Custom Query to show posts from last x years
- Query Custom Meta Value with Increment
- How to know which one is the main query?
- Get posts by meta data OR title
- Perform query with meta_value date
- Using is_main_query to select custom post type on certain page
- WP_Query ordered by custom field that is a date string?
- get query’s query string
- Meta Query with date and time on the same Day before given time
- get_the_title($postID) OR get_the_title()?
- Display Posts by modifying the where clause only for my query
- What is an efficient way to query based on post_meta?
- SQL query equivalent to WP User Query
- How do I create my own nested meta_query using posts_where / posts_join?
- What’s wrong with this WP query?
- Stop all SQL_CALC_FOUND_ROWS wordpress queries
- How to count post meta key values for all posts in database
- How to use filter hook posts_join for querying taxonomy terms in posts_where?
- Best practice for multiple queries on page
- Group posts by meta_key
- How to Get All Posts but the Private ones?
- How to search for posts IN OR title OR content OR author?
- WP_Query hit max joins… How else can I build a search function that uses custom fields?
- Would this post meta be better added to the post table rather than post_meta table
- How to query ‘posts_per_page’ to display a different blog posts index template?
- How to find out what “Blog pages show at most” is set to [duplicate]
- How to find if a post with custom_field == X exists?
- Order By Multiple Meta Fields
- meta_query on a date range using an array of values
- WP_Query Performance Issues with meta_query
- Multiple search queries on one page
- if statement on database query
- Should close $wpdb via $wpdb->close()
- How to show only one post for each categories of taxonomy of custom post that contains a specific custom field
- How to speed up wp_query, took more 5s to run against 100k posts
- Pass the same object to multiple widgets in a template with one query
- Get the post permalink within the loop but without additional DB query
- Filter WordPress posts by between parameter
- Retrieve or Query Pages by ID
- SQL User Query by Multiple Roles using PHP
- Retrieve featured image (thumbnail) url from multiple posts with one query
- WP query exclude post within the last month / only show over 1 month old
- WordPress query for most recent posts from multiple categories
- WordPress Query is taking more then 20 second and stuck on creating index
- How do you query wordpress posts using a math formula between multiple meta field values?
- How add a custom posttype name using ACF field to a query post array
- How to implement time filter to show random post 1 month for one category and 3 months for other categories
- Too many posts cause slow load when paginating
- Get the Plugin Which Triggered a MySql Query in WordPress?
- Page navigation doesn’t show when query category
- Multiple instances of Featured Image Query
- How To Get Some Data From WordPress Database Using WordPress $wpdb Query?
- How can I pick a single post from the latest 3?
- 2 loops on page – one with orderby rand second orderby date
- How do you Query posts with nothing in common?
- greatest() function returns undefined property
- Query post with meta_query where date is not in future
- What’s faster? One big query, or several smaller ones?
- Next/Prev posts on same page
- Mysql query LIKE not working
- How to get posts on a specific date – WP Query
- Using WP_Query and WP_Meta_Query Outside of WordPress
- How WordPress attaches its Featured Images with posts?
- Custom category search box for WordPress
- How to find exact match for search term in WP_Query? What is the additional string added in LIKE query in WP_Query?