Post formats are actually terms of the taxonomy post_format
. I have done a post about this what taxonomies are and their hierarchies which you can check out here
To get a list of all terms under the taxonomy post_format
, simply use get_terms
and var_dump()
the result
$terms = get_terms('post_format','hide_empty=0');
?><pre><?php var_dump($terms); ?></pre><?php
This will print
array(5) {
[0]=>
object(stdClass)#207 (9) {
["term_id"]=>
string(3) "142"
["name"]=>
string(5) "Aside"
["slug"]=>
string(17) "post-format-aside"
["term_group"]=>
string(1) "0"
["term_taxonomy_id"]=>
string(3) "142"
["taxonomy"]=>
string(11) "post_format"
["description"]=>
string(0) ""
["parent"]=>
string(1) "0"
["count"]=>
string(1) "0"
}
[1]=>
object(stdClass)#310 (9) {
["term_id"]=>
string(3) "129"
["name"]=>
string(5) "Audio"
["slug"]=>
string(17) "post-format-audio"
["term_group"]=>
string(1) "0"
["term_taxonomy_id"]=>
string(3) "129"
["taxonomy"]=>
string(11) "post_format"
["description"]=>
string(0) ""
["parent"]=>
string(1) "0"
["count"]=>
string(1) "0"
}
[2]=>
object(stdClass)#309 (9) {
["term_id"]=>
string(3) "105"
["name"]=>
string(7) "Gallery"
["slug"]=>
string(19) "post-format-gallery"
["term_group"]=>
string(1) "0"
["term_taxonomy_id"]=>
string(3) "105"
["taxonomy"]=>
string(11) "post_format"
["description"]=>
string(0) ""
["parent"]=>
string(1) "0"
["count"]=>
string(1) "0"
}
[3]=>
object(stdClass)#308 (9) {
["term_id"]=>
string(3) "128"
["name"]=>
string(5) "Quote"
["slug"]=>
string(17) "post-format-quote"
["term_group"]=>
string(1) "0"
["term_taxonomy_id"]=>
string(3) "128"
["taxonomy"]=>
string(11) "post_format"
["description"]=>
string(0) ""
["parent"]=>
string(1) "0"
["count"]=>
string(1) "0"
}
[4]=>
object(stdClass)#307 (9) {
["term_id"]=>
string(3) "106"
["name"]=>
string(5) "Video"
["slug"]=>
string(17) "post-format-video"
["term_group"]=>
string(1) "0"
["term_taxonomy_id"]=>
string(3) "106"
["taxonomy"]=>
string(11) "post_format"
["description"]=>
string(0) ""
["parent"]=>
string(1) "0"
["count"]=>
string(1) "0"
}
}
One thing though that I want to highlight, standard
is not a post format, which is a let down. Any post without a designated post format should actually be assigned a post format default. The problem is, if you need only posts that don't have a special post format, you need to run a tax_query
and exclude all posts that does have a post format.
So, to get posts from a certain post format, you can run a tax_query
with WP_Query
Example to get all posts from video post format:
$args = array(
'post_type' => 'post',
'tax_query' => array(
array(
'taxonomy' => 'post_format',
'field' => 'slug',
'terms' => 'post-format-video',
),
),
);
$query = new WP_Query( $args );
If you need to get posts without any post format attached, you'll need to do something like
$args = array(
'post_type' => 'post',
'tax_query' => array(
array(
'taxonomy' => 'post_format',
'field' => 'slug',
'terms' => array('post-format-video',' post-format-quote', 'post-format-gallery', 'post-format-audio', 'post-format-aside' ),
'operator' => 'NOT IN',
),
),
);
$query = new WP_Query( $args );