WP_Query: Exclude hidden products from WooCommerce product list

Important: The following only works for WooCommerce versions less than 3.0. For a more up-to-date answer please see the other answer by kalle. WooCommerce save this data as metadata so you’ll need to run a Meta Query against the name _visibility. Something like: ‘meta_query’ => array( array( ‘key’ => ‘_visibility’, ‘value’ => ‘hidden’, ‘compare’ => … Read more

Get posts from Network (Multisite)

I created a plugin which does something similar (called Multisite Post Display https://wordpress.org/plugins/multisite-post-reader/ ) . It displays posts from all multisite sub-sites. The code in there might be helpful for what you are doing. You are welcome to dig into it and use the code to help with your project. (After all, I used other … Read more

WP_Query orderby one custom field then another in one query

According to https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters you want to specify it similar to the following code example: $args = array( ‘orderby’ => array( ‘title’ => ‘DESC’, ‘menu_order’ => ‘ASC’ ) ); $query = new WP_Query( $args ); This is supported from WordPress 4.0. For custom fields (post meta) you will need an added meta query, as detailed on … Read more

Custom Taxonomy and Tax_Query

First of all, you run register_post_type on init and register_taxonomy on after_setup_theme which is called after init. This means your custom taxonomy will not be available when registering the post type. I would suggest you remove the taxonomies keyword from the register_post_type arguments array, and just register the taxonomy manually afterwards. In your example code … Read more

WP JSON REST API (Ryan McCue) how to query posts with specific meta data with ‘AND’ relation?

Sorry for answering my own question but it may help some other devs too. I created this additional filter ‘json_query_var-meta_query’that returns the necessary arguments. function adjustQrry($data){ $args = array(); $args[‘relation’] = ‘AND’; foreach ($data as $key=>$value) { if ( ‘relation’ === $key ) { $args[‘relation’] = $data[‘relation’]; } if ( substr($key, 0, 3) === ‘key’ … Read more

tech