Currently you are looping through the array of categories retrieved with get_the_category()
and for each category you retrieve two posts. In stead I understand you want to pull two posts from one category only.
To do so, you would have to remove the foreach
loop and in stead define $category
as the first category in the array only, like this: $category = $categories[0];
Related Posts:
- How to add Text before my Custom Term and hide it when empty
- admin panel – How to remove “delete” button from category editing page
- Category Page Displaying all Pages
- Get parent category name when only child category is applied to a product
- How to move a post from one category to another
- How to enable HTML tags in category description without breaking the category page
- Multiple Tag Filtering
- How can i create a function tag in my plugin
- Trying to show the category of a post in the post display
- Create category after theme setup and modify the default one
- Link to index.php from home.php?
- How does Permalink work with the AMP plugin after Removing Parent Permalink Catalog from Posts
- How to Link to category titles if it is in the single post content?
- Polylang and template files
- How can i show specific Category List?
- Notice: Undefined variable
- Add code to the header of posts by particular author
- Hide a specific category title from displaying on site
- How to show category just on specific pages?
- Display specific page if user signed in
- Show subcategory name selected in specific category woocoommerce
- How to filter specific element of an array in wordpress/php?
- Return to the beginning of the results of a for loop
- How to get Post sidebar & footer including html like get_the_content() which only gets content section?
- Exclude category and post from loop in custom category.php
- Admin backend, show post from a category and exclude the posts from subcategories
- Populate Posts based on category selected using AJAX that means without page refresh
- All categories options or All categories not Populating
- random woocommerce categories are not showing when count enabled?
- Exclude a category slug on pagination
- Customizing the output of the archive and category widget without altering the original behavior of the widget
- Custom content using in_category
- How to Retrieve All Category Images on Front-End
- Displaying 3 Category Posts differently
- Multiple if statements with else for get_the_category [closed]
- PHP drop down menu for my get_category child of
- Short code into PHP
- PHP get_category() function redeclared
- Widget Logic – display on page and all child
- Code works on page-example.php by not category-example.php
- Need Quick Help With Product Category Page
- List categories assigned to a post
- get_category display only 1
- Unable to get Post Category Name and URL
- How to list categories by page id in wordpress
- WordPress using get_term to retreive slug not working as expected
- How to add style in functions.php depending on conditions?
- Showing the project type in HREF
- How do I display Category titles on a WP Page?
- Rearrange get_categories array compared to another array
- Front end post submissions do not get submitted in the category
- problem with category menu, it doesn’t want to show link
- if user is admin display admin link and logout link else display logout only
- Add code only for blog posts
- How to define Og Meta Tags in header using conditions [duplicate]
- If Month=Particular month display content [closed]
- Make an array listing custom taxonomy
- Get category id for a custom category and display it in a class
- Saving category as insert post
- Trying to exclude posts from a category on the home page
- Search in particular category in wordpress
- Query seems to be duplicated
- Top menu disapears in Category Pages when filtering using ACF
- Is there a way to randomize and connect a background and header image?
- Trying to see if page is category or single and displaying title with appropriate heading tag
- wp_get_archive for category returning different URLs on different but similar sites
- Showing Subcategory’s Name and Link Instead of Parent Category’s
- Error trying import one category on page
- !in_array doesnt recognize category
- get_category only returning details for ‘uncategorized’
- dynamically filter by category via sub-menu
- How to change links in the 3 main categories, on widget category, to a javascript function call
- How to echo a different field if another field is empty?
- Remove the_content From Loop
- Adding else if conditional statement to purchased theme
- Category List in Theme Options Page
- Get unique post in parent category
- how to set category name for a post
- Code that displays images – images get shown multiple times
- Incomplete term slugs output from a foreach loop with get_the_terms
- category & sub category order issues in wordpress
- Conditional in foreach loop is outputting content twice
- Hide empty categories from get_categories
- Display post of specific category on page
- Displaying categories
- on category page get name of category as a string
- WordPress categories not working throughout site
- Advanced custom fields Repeater conditional statement not working [closed]
- Fix incorrect related posts code snippet
- Remove /category/ from category (archive) page URLs (without using a plugin)
- Display a list of posts corresponding to a category
- Product Category Page in Full Width
- child category under correct parent
- Display featured posts first, then display all others within a specific category in WordPress
- Help with get_categories code
- Is it possible to go to the next post in the same category?
- Side bar only if it’s not a single post or a specific page
- Can’t assign menu parent id or menu item breaks
- WooCommerce: Custom dropdown for variation selection
- Prevent publishing of uncategorized posts