Organizing and grouping an array by year
if you fix your date format to be yyyy-mm-dd they’ll just naturally order themselves and you won’t have to do all this complicated output.
if you fix your date format to be yyyy-mm-dd they’ll just naturally order themselves and you won’t have to do all this complicated output.
Use get_posts instead – You can use the function get_posts() to get all the posts as array. This function accepts almost all parameters that of query post’s. Example – $args = array( ‘numberposts’ => 3,’category’ => 3 ); $homePost = get_posts( $args ); $one = $homePost[0]; $two = $homePost[1]; $three = $homePost[2]; //print_r($one); // lets … Read more
Based on several different answers, with a SPECIAL thanks to EAMann‘s similar answer – here’s the method I followed. Using new WP_Query instead of query_posts for this page. Defining the query variable ($main_query) as global. Querying a temp array ($temp_featured) with my featured posts. Creating an array with only the IDs of the `$temp_featured’. Note … Read more
The code you posted is an incomplete copy/paste of the code from the tutorial you linked. labels is a parameter within the $args array: $labels_array = array( ‘name’ => _x(‘Books’, ‘post type general name’) ); $args = array( ‘labels’ => $labels_array ); register_post_type( ‘book’, $args ); $args is an array that contains an array of … Read more
get_user_meta() with omitted key argument will return all data for the object. Trying to retrieve metadata selectively is usually pointless optimization from performance point of view, since everything built on Metadata API tends to just query all data anyway and cache it (which in turn object cache plugin makes persistent and snappy).
You’re going about this wrongly, I think. The theme_location parameter for wp_nav_menu() is a template location – i.e. a physical location in the template, as defined/registered by the Theme. It’s not designed for an arbitrary number of locations based on arbitrary user content. If you want to output category-specific menus in specific template locations, you … Read more
The answer by felipelavinz assumes that there is an array of dates stored in the post_meta of each post, but the way I read your question and sample code it seemed as though you have one date specified per post? If this is true (one date per post) then the following would suit you better … Read more
Please try this instead: $args = array( ‘post__in’ => $post_ids, ); $posts = get_posts( $args ); Lesson learned: Always check your PHP scripting errors! 😉 Check for example this Codex page on debugging.
You are looking at type casting: http://php.net/manual/en/language.types.type-juggling.php What the code does is caste the value returned by get_option() to an array. It is being done so that array_merge() works correctly and doesn’t trigger warnings/errors. That much is pure PHP and is off-topic. The only reason I chose to answer rather than to post a comment … Read more
It’s not recommended to use query_posts(), check for example this warning note in the Codex: This function isn’t meant to be used by plugins or themes. As explained later, there are better, more performant options to alter the main query. query_posts() is overly simplistic and problematic way to modify main query of a page by … Read more