I’m not 100% sure if I get you right, but maybe this will solve your problem:
add_filter( 'wp_nav_menu_items', 'fx_user_menu', 10, 2 );
function fx_user_menu( $items, $args ) {
if ($args->theme_location == 'primary') {
$myposts = get_posts( array(
'category' => <YOUR CATEGORY ID GOES HERE>,
'posts_per_page' => 5
) );
foreach ( $myposts as $post ) {
// you should not use the_title and the_permalink outside of The Loop - they won't work correctly
$items .= '<li><a href="' . get_permalink($post->ID) . '">' . apply_filters('the_title', $post->post_title) . '</a></li>';
}
}
return $items;
}
Related Posts:
- What Defines What Category A Post Picks (if in multiple)
- WordPress menu that shows all posts in a certain category like w3schools
- Mark menu item as current-menu-item for category
- How to list recent posts in a wp nav menu?
- Un-highlight Blog Menu Item when Category Menu Item is Selected
- wp_list_categories() Exclude All Categories Except One
- WordPress – When visiting a `single post/ single.php` my category menu item link becomes active
- I want to add the 10 most recent posts under a parent category on the main menu
- How to add class to specific navbar item when post parent category is in specific category
- Automatic Table of contents with categories and posts
- How to remove category and other tags from posts page
- How to display related posts from same category?
- How to show related posts by category
- Display all posts from specific categories on a page
- Exclude posts that only have the ‘Uncategorized’ category [duplicate]
- How to disable Uncategorized category URL?
- Add role that restricts user to post in specific category
- Count posts in category including child categories
- Show Custom Taxonomy Categories, Listing of Posts, and Single Post via AJAX
- Display most recent post in category instead of archive?
- Archived Posts in Wrong Category
- Display all posts under child sub category in sidebar on post page?
- How do I get the slug of a custom taxonomy category of a post?
- Featured Posts for Category Pages
- Authors in menu, template list post by author
- Count to how many categories a post belongs to
- How can I remove posts of a certain category from homepage after a specified time period?
- Create dropdown list post
- Add icon/badge next to posttitle of specific category
- Edit custom post type admin menu link
- How to display WordPress archive into three columns [closed]
- Get mixed category random posts
- Using wp_list_categories like the the_category (showing just current categories of a post)
- Should I use posts or pages in this scenario?
- How to allow users to post only in certain category and hide elements from edit page?
- Need help with category listing!
- Prepending %category% onto default posts fails
- List all categories with featured image from post?
- Dynamic dependent Dropdown lists for categories, sub-categories and posts
- How to display two blog categories as separate sections on one page?
- How to make the first post in the loop be styled like a “new / featured” post?
- why does wordpress ignore the post args?
- get posts from Custom Post Type & Category
- How can I list posts by author?
- How to enable custom Shortcodes in Post Category Description? [duplicate]
- Sort by last word in title
- How to call posts under a specific category on static front page?
- Give posts a particular template based on the assigned category
- Having pages after specifying post_type post
- Post-Archive like a page in a specific subdirectory
- How to show a featured image inside a post in only 1 single category
- Highlighting Current Category in the Archive and Feeds page
- Get current taxonomy and display query accordingly
- Geting error in post and category [closed]
- Display most recent posts in category with Twenty Ten theme widget
- Display a specific category in a focused area of my site
- How to make ajax load posts from the current category?
- Menu does not foward to the linked posts
- How can I create a ‘sub-blog’ which has its own sidebar on individual posts?
- Does having category name in permalinks affect SEO when having a post in multiple categories?
- How to 301 redirect from url with post id to permalink with post name (slug)?
- Create/Set Category as Title of Post
- How to display related post from same category in single.php
- Save All Post Permalink From A Specific Category into a .txt file
- show image gallery in archives or category page
- Page with Category Returning 1
- Using WP page password protection as defacto login
- get current index of post content in category page
- Get 5 most recent categories
- Dynamically load posts based on category
- Get Categories & Posts With Type Article
- Set multi posts random categories and tags
- Keep highlight on menu item with post pages
- Add new post only in assigned category
- Changing the Category for all posts of an Author
- Unable to uncheck a category in a post
- Admin Post List Only Show One Category
- Hiding menu on mobile only when viewing posts?
- Add category attribute to custom recent post shortcode
- Same sidebar in all posts as in the category
- How do I list categories and the common categories for posts beneath those categories?
- Latest Posts not in the right order
- Retrieve latest post by multiple categories with ID
- How to set a link to custom archieve page
- How to Include a common category in a custom Category Search
- How to display only one post on first category page and rest on next pages?
- Can’t assign another category other than Uncategorized int he following front end post submission form?
- How do i put a dropdown list of ALL my post in the sidebar menu?
- Viewing category won’t show up Custom post type posts
- Show Title/Date/Excerpt of first post & only Title for rest in Query [duplicate]
- Listing category and its posts one by one
- Print out one of 2 post category [closed]
- How to get if category has posts?
- Show some texts in posts belonging to Specific category
- Dynamic Menu Item
- Sort Posts Alphabetically Based on Specific Category (Divi)
- I have a website issue I am trying to resolve
- How to sort posts alphabetically based on a specific parent category
- Category and archive issue
- Preset category checkbox from URL parameter when creating new post