Hot answers tagged

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 ...


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 ...


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 ...


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. ...


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


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 ...


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( ...


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 { ...



Only top voted, non community-wiki answers of a minimum length are eligible