CPT archive page – show one post from each taxonomy term

So I went ahead and did the multiple loop thing, as I had done before. I’m always interested in seemingly cleaner/simpler solutions, but sometimes you just have to keep moving. This is the code I’m using: <?php $args = array( ‘post_type’ => ‘projects’, ‘project_category’ => ‘websites’, ‘orderby’ => ‘menu_order’, ‘showposts’ => 1 ); $posts = … Read more

Query Custom Post Type by Taxonomy

Use get_terms() with child_of (accepts numerical ID of parent term) argument to retrieve child terms and then loop through them and on each iteration use current term in the loop. Code example (not tested): $child_terms = get_terms( array( ‘child_of’ => $cameras_term_id ) ); foreach( $child_terms as $term ) { $args = array( ‘post_type’=> ‘rental_gear’, ‘type’ … Read more

Get newest created custom category (get_term_by and variables) (outside Loop)

You can use this function http://codex.wordpress.org/Function_Reference/get_categories The parameters passed are basically the same except it returns an object containing all the category information. Using this function can replace the first 4 lines of your code. Now your final code becomes: $getID = get_categories(‘taxonomy=issue&number=1&orderby=ID&order=DESC’); $currentID = $getID->term_id;

Custom post rewrite rule not working

The undesirable answer I alluded to in my question is to intercept WordPress’ routing and URL generation. Manipulate the URLs with: add_filter(‘post_type_link’, ‘my_post_link’, 10, 3); function my_post_link($permalink, $post, $leavename) { if ($post->post_type == ‘publication’) { $year = date(‘Y’, strtotime($post->post_date)); return site_url(“/publications/$year/$post->post_name”); } return $permalink; } Then intercept the routing: add_action(‘template_redirect’, ‘my_template_redirect’); function my_template_redirect() { if … Read more

Metabox does not show in custom post type

The custom post type is being register as name, not snippet as is being called in add_meta_boxes action. This is because a PHP var is passed inside single quotes and it is not being interpreted. Change this: register_post_type(‘$name’, $args); To: register_post_type($name, $args); This also work: register_post_type(“$name”, $args); But never pass PHP variables inside single quotes … Read more