Created
January 19, 2014 22:47
-
-
Save michaelschofield/8512037 to your computer and use it in GitHub Desktop.
An example of what the WP_Query() might look like to fetch all posts with the "LibTechGender" category that only have the "Link" post format.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Assuming a parent category called "LibTechGender" with sub-categories | |
like "Code of Conduct", "Impostor Syndrome," etc. Probably get more | |
nesty to separate by "Articles (Mine)" and "Articles (Others)," but | |
the point is it can be done with just categories. | |
*/ | |
// Fetch articles about the "Code of Conduct" | |
$args = array( | |
'post_type' => 'post', | |
'category_name' => 'code_of_conduct', | |
'tax_query' => array( | |
'relation' => 'AND', | |
// Get LibTechGender Posts | |
array( | |
'taxonomy' => 'category', | |
'field' => 'slug', | |
'terms' => array( 'libtechgender' ) | |
), | |
// and only Links | |
array( | |
'taxonomy' => 'post_format', | |
'field' => 'slug', | |
'terms' => array( 'post-format-link' ) | |
) | |
) | |
); | |
$the_query = new WP_Query( $args ); | |
// Drop all of the LibTechGender "Code of Conduct" in a list | |
if ( $the_query->have_posts() ) : | |
echo '<ul>'; | |
while ( $the_query->have_posts() ) { | |
$the_query->the_post(); | |
// Why "the_content()"? Presumably, the only thing in | |
// the post with the "link" format would be just the | |
// Title of the piece wrapped in a link. If that's it, | |
// you can just post the whole content. If there's a | |
// corresponding paragraph or review, then this can be | |
// changed-up just to extract the link. This example | |
// assumes the lazy way :). | |
echo '<li>' . the_content() . '</li>'; | |
} | |
echo '</ul>'; | |
} | |
// Reset the Query | |
wp_reset_postdata(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment