“tax_query” parameter not working with WP_Query

The tax_query parameter is an array of arrays, not just an array. This: ‘tax_query’ => array( ‘taxonomy’ => ‘video_type’, ‘terms’ => ‘episode’, ‘field’ => ‘slug’, ‘include_children’ => true, ‘operator’ => ‘IN’ ), Should instead be this: ‘tax_query’ => array( array( ‘taxonomy’ => ‘video_type’, ‘terms’ => ‘episode’, ‘field’ => ‘slug’, ‘include_children’ => true, ‘operator’ => ‘IN’ … Read more

Is it necessary to use wp_reset_query() in a WP_Query call?

Hi @janoChen: Simple answer: no. What follows is what the PHP code for the function wp_reset_query() from /wp-includes/query.php in WordPRess v3.0.4 as well as the functions subsequently called. You can see that it’s primarily about in modifying global variables. When you use new WP_Query($args) you will be assigning the return value from values to a … Read more

Nested meta_query with multiple relation keys

The question was for WordPress 3.0, but just in case someone has the same question for a more recent version, from WordPress Codex: “Starting with version 4.1, meta_query clauses can be nested in order to construct complex queries.” https://developer.wordpress.org/reference/classes/wp_query/#custom-field-post-meta-parameters So, that query should work on the current WordPress version.

Should I use Pre Get Posts or WP_Query

pre_get_posts will run the same query, so both will take same time. But, If you utilize pre_get_posts action you will save one or more SQL queries. Right now, WordPress is running default query and then you run your query with this function which replace the results of the default query (resulting, default query is of … Read more

How to store and receive variables in WP sessions?

Sessions aren’t enabled in wordpress by default, if you want to activate php sessions add this at the beginning of your functions.php: if (!session_id()) { session_start(); } You now can use $_SESSION[‘your-var’] = ‘your-value’; to set a session variable. Take a look at the PHP documentation on sessions. Update: There was a second answer, which, … Read more

tech