I think the most sane way and easiest way of doing this is to unset the first value in the returned array, and then adding it back at the end of the returned array before your foreach
loop
For this to work, you will need to sort your categories by ID as you need to take category ID 1 and add that to the back. Something like this will work
<?php
$args = array(
'hierarchical' => 1,
'orderby' => 'id',
'order' => 'ASC',
'include' => '13,21,41,1',
);
$categories = get_categories( $args );
$v = $categories[0];
unset($categories[0]);
$categories[0] = $v;
foreach( $categories as $cat) {
echo $cat->slug ;
}
?>
Related Posts:
- Inject post (from specific category) between posts in Loop
- Custom Loop through category menu to include sub categories
- How to exclude specific category from the get_the_category(); array
- Filter Select results based on selection
- Alert Bar section within WP loop is displaying even though there are no posts
- Display category name only once inside loop
- I’m trying to create an array with a foreach loop, but the array only stores the last item [closed]
- How do I remove a category from a wordpress loop>
- How to get the last category name of a child category?
- How to get current post category details inside “loop”?
- Problem with custom loop and wp_list_pluck [closed]
- Echoing a CSS class based on category of post in a list
- Do not duplicate posts with multiple categories in multiple loops
- Return to the beginning of the results of a for loop
- Exclude category and post from loop in custom category.php
- Error trying import one category on page
- Remove the_content From Loop
- Displaying post per day
- How to add active class to custom menu using while loop and wp_list_pages
- How to Populate the list of custom post type categories
- Php string not working in WordPress Functions.php [duplicate]
- Print html when custom field has value inside while loop
- get understrap pagination to work with custom query
- Error: array_map(): Argument #2
- When would you use $_post instead of $post?
- Way to display “Yesterday”, “Today”
- Must Use Plugin Causing Query Error
- Display all categories including sub categories
- Advanced Custom Fields: Post Object – Not returning data [closed]
- Category Thumbnail Display – How to display ONLY the main Category
- How can I add multiple ‘tax_query’ arrays via a loop?
- How to use transient in this code for related post?
- Second level subcategory
- What is an equivalent of single_cat_title for getting the slug of the category?
- Move category description below post list in blog
- Blog posts repeat
- How to set variable, pass it to a partial file and remove it after?
- Setting default category base on theme activation
- Checkbox doesn’t stay checked, conten
- List posts that don’t have a specific tag?
- Add content after the first post in WP Loop
- Display an image if odd number of posts in grid
- How to loop through all the attached images in a post, and get their url one by one
- 2nd page displaying the exact same posts as my first page (minus the very first post)
- Is the 404 page automatically displayed if a loop returns nothing?
- Show recent posts starting at a specific number archive
- How to pass a variable to get_template_part that’s updated every time the template part is called?
- Use get() method to grab all categories and output inside another method
- use loop to return blog details
- Show all tags within a category?
- WP Query Leads to 502 Bad Gateway (Timeout Because Query Takes Too Long)
- How to add post meta in while loop?
- Displaying list of posts in category page
- Calling function in loop causes repeat data
- WordPress call post-ID in jquery
- How to Generate a list of Most Commented post?
- How to pick “full/thumbnail” images in the loop?
- How to Fix an Archive.php That Displays All Posts?
- is user member of a group, show them categories [closed]
- How to add ASCII symbol after each recent post [closed]
- Using multiple variables to assign categories to an array
- Search.php gets metadata from first post
- the_post(); prints out style text into my HTML?
- Pagination at category doesnt work with same name of page
- display the months of a specific category
- Child-Theme Category View with modified permalinks (%category% removed)
- update_user_meta as multiple value but with same meta key
- How to move a post from one category to another
- Create category after theme setup and modify the default one
- Accordion headings cuts off to second line on collapsing a accordion heading (used acf repeater)
- WordPress Recent Posts – Loop
- ACF background-color per post in a WordPress loop
- Advertisement in Loop Posts wordpress
- Displaying 3 Category Posts differently
- Adding custom PHP to existing loop in Genesis
- How to Pass Current Taxonomy Terms into new WP_Query?
- How to list categories by page id in wordpress
- For each 3 posts, show a different post type
- WordPress using get_term to retreive slug not working as expected
- Showing the project type in HREF
- Loop returns more items than exist?
- Modify category archive page loop on functions.php
- Front end post submissions do not get submitted in the category
- WP_Post is not from correct array
- Post formating on Home page
- divide custom field values in div every two values
- Saving category as insert post
- Limit ads appearing more than three times
- Trying to exclude posts from a category on the home page
- Pagination on Custom Loop
- Showing Subcategory’s Name and Link Instead of Parent Category’s
- What is the best way to get the first few post from WordPress in different divs using a loop?
- Custom single.php files for different post formats
- Troubleshooting “loopback requests that take too long”
- on category page get name of category as a string
- WordPress categories not working throughout site
- Remove /category/ from category (archive) page URLs (without using a plugin)
- Loop on a wordpress Page instead of content coming from the WP text editor
- Help with if/else loop [closed]
- Saving meta box data from selected option’s value in database is not working