How do I query all posts of one type across my multisite installation?

Yes but not in a single query, e.g.: if(is_multisite()){ global $wpdb; $blogs = $wpdb->get_results($wpdb->prepare(“SELECT * FROM $wpdb->blogs WHERE spam = ‘0’ AND deleted = ‘0’ and archived = ‘0’ and public=”1″”)); if(!empty($blogs)){ ?><?php foreach($blogs as $blog){ switch_to_blog($blog->blog_id); $details = get_blog_details($blog->blog_id); $q = new WP_query(); if($q->have_posts()){ while($q->have_posts()){ $q->the_post(); // do things break; } } wp_reset_query(); restore_current_blog(); … Read more

Meta Query with AND & OR?

Sorry, doesn’t work that way. The “simple” meta parameters are converted into part of the meta_query as a whole. So it’s not a separate thing, and your OR relation applies to it as well. Your query thus is not possible with the normal query system, because you want to mix ANDs with ORs (you want … Read more

Group WP_Query by category

You could look at modifying the WP_Query with a SQL command to group them, but that’s a bit beyond my current MySQL, however, I’ve always done it by running a foreach on the taxonomy itself with this http://codex.wordpress.org/Function_Reference/get_categories Here’s some sample code: <?php global $post; $current = get_the_ID($post->ID); $cargs = array( ‘child_of’ => 0, ‘orderby’ … Read more

How to get posts from two categories with WP_Query?

In my experience using ‘posts_*’ filters (‘posts_request’, ‘posts_where’…) in combination with str_replace / preg_replace is unreliable and unflexible: Unreliable because if another filter modify uses one of that filters, in better case one gets unexpected results, in worst cases one gets SQL errors. Unflexible because changing an argument, e.g. ‘include_children’ for categories, or reuse the … Read more

How to add multiple custom URL variables?

I pretty sure this filter lets you add an array of variables. I’ve not tested this: function add_custom_query_vars( $vars ){ $vars[] = “variable1”; $vars[] = “variable2”; $vars[] = “variable3”; //… etc return $vars; } add_filter( ‘query_vars’, ‘add_custom_query_vars’ ); Or another way of doing it would be to do this: function add_custom_query_vars( $vars ){ array_push($vars, “variable1”, … Read more

How to check if I’m on a custom post type archive in the admin area

Here are three possibilities, based on the /wp-admin/admin.php file: Method #1 There are the global $pagenow and $typenow available: global $pagenow, $typenow; if( ‘my_venue’ === $typenow && ‘edit.php’ === $pagenow ) { // … } Method #2 Then there’s the current screen, also set in the admin.php file with set_current_screen(); $screen = get_current_screen(); if( is_a( … Read more

Order by Category and Post in WP custom Query

To do this you have first get all the category in ascending order by get_categories then you have to pass the cat_id in WP_Query to get the post related with that category. $args_cat = [ ‘orderby’ => ‘name’, ‘order’ => ‘ASC’, ‘hide_empty’ => 0, ]; $categories = get_categories($args_cat); //print_r($categories); if (!empty($categories)): foreach ($categories as $category): … Read more

tech