Query Builder - Query Post by Pro 'Format' and Exclude current

Got a few questions around building a custom layout for post pages:

  1. I want to only pull a loop of posts that are formatted as “Video”. I don’t see anyway to do that. I suppose if I need to I can use ACF and CPT to make a Video Post Type, but I’d rather do it with the built-in if possible.

  2. This loop is for an “Other videos” section of a page, and I’m pulling 3 random videos like the current. However, I want to be sure that the list doesn’t include the current. (Why show them a link to the video they are already watching?) Is there a way to do that in the query? Or is there another way to pull it off? Maybe using the conditions?

Hi @MintCondition,

Please find the answer to your queries below.

  1. You need to use the tax query using the Query String option to get the posts based on the post formats, please check this article to build your query
  1. To exclude current post, you need to add the ‘post__not_in’=> array( ‘{{dc:post:id}}’ ) to the above query.

Hope it helps.

Drilling into point 1, can you explain how the WP_Query translates to the Query String in the looper? Specifically, I think the WP_Query would be something like :
‘post_type’ => ‘post’,
‘tax_query’ =>
‘taxonomy’ => ‘post_format’,
‘field’ => ‘slug’,
‘terms’ => array( 'video '),
Maybe… I might have dorked that up.

But how do I convert that to the syntax the QS is looking for? I’ve tried a few guesses but none seem to return anything, so I’m doing something wrong.

Hi @MintCondition,

I would like to refer to my colleague Kory’s comment in the following thread, which may be helpful to you to create the Query String based on your argument array and tax query.

Hope it helps.

Ok, so that was more complicated than I felt like it needed to be, but for anyone that finds this thread later, here’s the query I came up with that is working:


The hard bit was digging into the tables to figure out that 1) the actual term is “post-format-video” and 2) realizing that while “post_format” uses an underscore as a separator, “post-format-video” uses a dash. Anyway, I got it working now. =)

Ok, so how to add that to the above query, because it’s not working as I expect:


How do I attach the post__not_in bit?

Hello @MintCondition,

Please use it like this:


Hope this helps.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.