How do I Use Multiple Loops with WP_Query?

As Toscho mentionned above, you didn’t close your if and while. When in doubt, indent your codes to avoid confusion. $my_query = new WP_Query( $args ); if ($my_query->have_posts()) : while($my_query->have_posts()) : $my_query->the_post(); endwhile; endif; wp_reset_postdata(); /* The 2nd Query (without global var) */ $query2 = new WP_Query( $args2 ); // The 2nd Loop if ($query2->have_posts()) … Read more

Date range filter for manage posts list on edit.php

WordPress support advised me you can use the same parameters on the URL as WP_Query() accepts. http://codex.wordpress.org/Class_Reference/WP_Query#Time_Parameters You can’t pass a date range. The best you can do is pass specific dates. For example, edit.php?s&post_status=all&post_type=post&action=-1&m=201301&cat=0&post_format=0&paged=1&mode=list&day=1 will show all posts from the 1st day of the current month. When I told this to our content manager … Read more

Is it possible to get all term items from a custom taxonomy regardless of post attachment status?

If I understand right, you need all attachments (attached or not) with specified term? $args = array( ‘post_type’ => ‘attachment’, ‘my_taxonomy’ => ‘my_taxonomy_term’ ); $my_query = new WP_Query( $args ); if( $my_query->have_posts() ): while ($my_query->have_posts()) : $my_query->the_post(); // your stuff here endwhile; } // Don’t forget to reset wp_reset_postdata(); WP_Query Taxonomy Parameters.

Top level parent taxonomy ID

In general to get the posts of your custom post type you need to query post_type, if you want only the categories you could just pull the categories instead of the entire post type. <?php query_posts(array( ‘post_type’ => ‘CustomPostType’ )); ?> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <?php … Read more

Hook to change Custom Tag Taxonomy Links?

If anyone else is looking for this in the future, the result I came up with is this one… /* Filter Custom Taxonomy Tag HTML Links */ function custom_term_link_url($content) { $current_path=”news-tag”; $new_path=”news/tag”; $content = str_replace($current_path, $new_path, $content); return $content; } add_filter(‘term_link’, ‘custom_term_link_url’); It will run code on Taxonomy Links. I still need to add in … Read more

wp_insert_post not updating custom taxonomy selected if logged in as a subscriber

It’s because within wp_insert_post current user capabilities are checked before adding the terms: if ( current_user_can($taxonomy_obj->cap->assign_terms) ) wp_set_post_terms( $post_ID, $tags, $taxonomy ); to get around this, use wp_set_object_terms instead after wp_insert_post to add the terms: $new_post = array( ‘post_title’ => $postTitle, ‘post_content’ => $post, ‘post_status’ => ‘publish’, ‘post_date’ => date(‘Y-m-d H:i:s’), ‘post_author’ => $user_ID, ‘post_type’ … Read more

How to Put Custom Taxanomy Meta Box in Main Column

Unfortunately WP is hardcoded to generate taxonomy metaboxes in that side location. It is tad fragile, but possible to throw generated data around from one location to another: add_action( ‘add_meta_boxes’, ‘move_taxonomy_metabox’ ); function move_taxonomy_metabox() { global $wp_meta_boxes; $taxonomy = ‘test’; $metabox_key = ‘tagsdiv-‘ . $taxonomy; // or $taxonomy . ‘div’ if hierarhical if ( isset( … Read more

Custom user taxonomies fail when i register multiple taxonomies

Thankfully I found an easy solution to this problem. When outputting or terms as checkboxes/radios/whatever, we need to change this: <?php checked( true, is_object_in_term( $user->ID, ‘YOUR-TAX’, $term ) ); ?> To this: <?php checked( true, is_object_in_term( $user->ID, ‘YOUR-TAX’, $term->term_id ) ); ?> This is from the function in my original post. YOUR-TAX is where you … Read more