The problem probably comes from whenever a $post
has no terms set. You need to set $brand = array()
outside your IF
statement, add it just under get_the_terms()
. At that point it also wouldn’t hurt to wrap your switch
statement in a if( ! empty( $brand ) ) {
Another problem I see with this code is that you’re adding your term IDs to an array, then converting that array to a string, then switching them on an integer. So if you have a post assigned to Term 3
and Term 5
, whenever it hits your join it will convert to string: '3, 5'
and test the entire string against each case:
'3, 5' == 3
-> False
'3, 5' == 5
-> False
etc. You may just want to get the First term and test on that.
Related Posts:
- Showing random content / pictures from earlier posts in a sticky post?
- Avoid duplicate post from same Taxonomy
- Loop parent terms {display posts} AND loop child terms {display posts}
- The loop starting at a certain ID
- linking to post outside the loop
- Loop through posts by each term and exclude duplicate posts assigned to several terms
- View post with specific category id and name which I selected in the backend (drop-down option)
- Print Current Post Index number within Loop
- Get current post id in functions.php
- rewind_posts() – what actually the use of it, and where using is required or preferred?
- How to show list of posts by author and category?
- Override the default number of posts to show for a single loop?
- Exclude posts that only have the ‘Uncategorized’ category [duplicate]
- WordPress Number of Posts Not Changing With posts_per_page
- Are all ID’s used unique?
- Find most recent authors
- Get the author of the latest revision
- Strange switch_to_blog() issue
- Multiple loops in same page, without duplicate content
- loop not displaying posts on custom template page
- How to Display Post View Count
- get post id in while loops outputting page id
- Undefined variable post_id in custom quick edit coloumn
- Adding Multiple Values to a Post Meta Key
- Displaying the number of posts in a custom loop (without including the number of posts of a loop below)?
- The correct way to call posts with ajax
- Converting multiple loops into one single loop with pagination
- How would I get 1 latest post from a query for 5 posts?
- Getting post id from wp_insert_post_data function?
- Does an article (post) id ever change?
- How to get the post’s parent ID?
- Is there a better, more efficient way to get the post id outside the loop?
- Alternating post layout
- Check to see if specific loop has less than certain amount of posts
- How blog page in WordPress works : blog page retrieve first post ID
- Adding specific post category between posts in loop
- Get posts of ONE taxonomy term of custom post type
- Multiple loops are not reset
- current post with current author
- Exclude category from
- Blog post per page setting conflicting with custom WP_Query?
- How to exclude latest x posts from a paginated query?
- How to get next post ID?
- Pausing and Resuming WP_Query results
- Post Loop Missing Most Recent Post
- How to : pagination in 3 different custom loops on the same page
- Sharing post from archive page (loop) doesn’t work
- Start WP Pagination From Number 1 in URL
- sql select for post_title and a term name
- Use two different post_per_page limits with infinite scroll
- Wrong post title displayed from loop
- Change all author links in Blog roll
- How to I retrieve the ID from the Posts page?
- Crazy Question – Updating Post ID
- Showing categories and subcategories with posts
- Get the amount of posts on a current page
- older blog posts not showing in new theme
- How to get posts published on the latest date?
- Page and post loop same template
- WordPress Query Posts From Category Post on Static Page
- Parent category / child category posts
- Loop through posts? Want to remove extra newlines in actual post HTML/content on backend
- How include css class based on post ( in loop ) slug?
- WordPress Loop: How to display recent posts in multiple divs
- How to display posts on custom page without declaring a posts page in reading settings?
- Cannot implement byline into posts container in single.php
- How to check if there are posts with the same tag
- Are post, page and category IDs unique to each other?
- Different number of posts per row in grid layout
- WP_Query of Category Not Showing First Post
- How come this loop is not working? [closed]
- Get a post’s ID
- Using the loop to set locations for all posts on a single google map
- How to get the post id (of the parent custom custom type) in a loop inside a widget?
- Want to change the post every three days with in specific category
- Separate top level categories on archive-product.php by meta
- While loop in functions.php outputting the_title() of each post on frontpage
- Shortcode for Comments and Comment Boxes in Post Loop
- Permalink Short code showing unnecessary link text inside the loop
- Get post slug and match with menu item slug to change css
- Display title of all custom posts from same taxonomy term on a custom post template
- Double loop output
- post->ID displays the same ID number for every post
- Posts are not showing up on next page.
- Only get post_id [duplicate]
- Post are not showing up
- How to make post button to a random post
- Advanced Post Display/Pagination/Ordering
- Keep post format class with isotope filter
- Make assigning post to a specific category equivalent to assigning it to all categories
- How to get all the terms of a post
- How to inject a post within a loop
- Sort by category and then date?
- Loop not allowing infinite scroll after post per page limit
- Customise the appearance of 4 specific post ID’s within the loop?
- what template-part to call, to have my post in the center of the page?
- How to show only the date, the title and a little “summary” of my WordPress post in my custom theme?
- How do I create a template page to show 3 blog posts?
- posts_per_page – Repeats only first posts ‘post__in’ array
- How to get post ID after removing that post?