New answers tagged

1

After some tweaking I've discovered that I've totally forgotten the relation into meta_query. so I've just added 'meta_query' => array( 'relation' => 'AND', $closed, $ends, $budgets, ), and it worked fine.


1

Give something like this a try: (it came from the same page you linked to, just scroll down a bit more). $args = array( 'post_type' => 'post', 'tax_query' => array( 'relation' => 'AND', // searches for posts meeting both conditions array( 'taxonomy' => 'midgets', 'field' => 'slug', 'terms' => array( ...


0

'meta_key=keyname' must also be present in the query so I think you'd want $args = array( 'meta_query' => array( array( 'key' => 'wpcf-stream', 'value' => $_POST['category'], 'compare' => '=' ) ), 'orderby' => 'meta_value', 'meta_key' => 'wpcf-stream', 'post_type' => 'half-day-course', 'posts_per_page' ...


0

You can use meta__value in orderby e.g. 'post_type' => 'tribe_events', 'posts_per_page' => -1, 'meta_query' => array( 'relation' => 'AND', 'event_title' => array( 'key' => 'post.title', ), 'event_id' => array( 'key' => 'EventVenueID', ), ), 'orderby' => 'event_title', Not tested but should work, this was introduced in ...


0

The WP_Query() custom field (i.e. meta) query can handle arrays for field values. You just need to add the compare key to your array: $args = array( 'numberposts' => -1, 'post_type' => 'post', 'meta_query' => array ( array ( 'key' => 'my_key', 'value' => 'target_value', ...


0

First things first, never use query_posts, it overwrites the main query and can cause unwanted side-effects. Use WP_Query instead. _wp_page_template is a post meta key, so the first thing we need to do is to load the value stored in that key for each page, using get_post_meta. That will give us the filename, which we can then try to load. $this_page = ...


0

In order to save the page template (part) from the admin, I would use custom meta field, and save the template_part name in each page/post. Then call the post meta in the template and pass it to get_template_part. // meta saved in admin is "child_template_type => "child_part_one" // where the meta_key = "child_template_type" // and meta_value = ...


3

Whenever the main query is available, which is for every front end page load regardless of which page/archive is loaded, you should use pre_get_posts to alter the main query's query vars before the SQL query is build and executed. This goes for each and every page where you need to alter the main query. This is the RECOMMENDED way to alter the main query. ...


4

query_posts() is useful in cases when there is no main query: calls to wp-admin/admin-ajax.php, wp-admin/admin-post.php or wp-login.php for example. Yes, you can achieve the same results there without query_posts() and slightly less compact code instead. But if you don't have to care about side effects, using query_posts() is acceptable.


3

In general, the query performed on the homepage, query_posts( 'posts_per_page=get_option( 'posts_per_page' ) and $q = new WP_Query( 'posts_per_page=get_option( 'posts_per_page' ) should have the same exact performance with very very little to no difference between them as all of the above are exactly the same by default (that is, have the same query ...


6

You ask: is query_posts really slower than some secondary query... The fact is that if you're calling query_posts() from a theme then it already is a secondary query. WordPress has already queried the database once to get a certain page then it hits your query_posts() function and queries the database again creating a second query and overwriting the ...


2

[somewhat rant] It is the standing core philosophy at this point that nothing is truly deprecated. Deprecation notice, while it is a nice to have, is just going to be ignored if the function will not actually be dropped at some point. There are many people that do not develop with WP_DEBUG on and will not notice the notice if there will not be an actual ...


7

I have just created a new trac ticket, ticket #36874, to propose the deprecation of query_posts(). Whether or not it will be accepted remains a good question. The real big issue with query_posts() is, it is still widely used by plugins and themes, even though there have been really good writings on the subject of why you should NEVER EVER use it. I think ...


0

As already said, your query arguments are slightly off - meta_query should be an array of arrays: $query = new WP_Query( array( 'category_name' => 'events', 'order' => 'DESC', 'orderby' => 'meta_value', 'meta_query' => array( array( 'key' => 'start_date', 'value' => ...


1

As per the given url http....url.../author/name?MediaTag=tag1, below code may helpful... if(isset($_GET['MediaTag'])) //It will check the value of MediaTag (from address bar after ?) { $tag1 = $_GET['MediaTag']; //Assigning value of MediaTag to the variable if($tag1) //Checking if variable have some value or not { ...


2

The solution is to use: 'taxonomy' => 'meal', 'field' => 'slug', 'terms' => 'breakfast' The taxonomy and terms are obvious, but why does field have to be slug? When you add taxonomy parameters, you can specify what 'breakfast' is-- via the field. It could be the term's ID, the full name, or slug. See the codex on Taxonomy Parameters



Top 50 recent answers are included