New answers tagged

0

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.


0

You cant export only categories (or taxonomies generally). Just export all content with Tools/Export and you can delete content except categories from xml.


-1

Have you looked into expire plugins ? https://wordpress.org/plugins/search.php?q=expire finally wordpress.org/plugins/post-expiring seems to have done the job.


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

You need to use the methods of your query instance, rather than the global functions (which are merely wrappers for the global $wp_query): if ( $query->have_posts() ) { $term = $query->queried_object; while ( $query->have_posts() ) : $query->the_post(); //Output my posts the_title(); the_content(); endwhile; ...


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.


0

Have you already looked at get_page_children? you need to pass the id of the child page and the $children_posts to it and it will return all childpages of it... what you need is: child-1->ID and an array with child-1, child-2 and so on


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


0

First, calculate the number of whole days from your start date, then take the modulus of this and the total number of posts in 'products'. This will give a 'post number' which you can use in the loop to show only the relevant post. So, if you have three posts $days_elapsed % $post_count would look like: | days | mod | -------------- | 0 | 0 | | 1 | ...


0

ok, I was close and I have solution: SELECT wp_posts.ID, wp_postmeta.meta_value FROM wp_postmeta INNER JOIN wp_posts ON wp_posts.ID = wp_postmeta.post_id INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) INNER JOIN wp_term_relationships AS tt1 ON (wp_posts.ID = tt1.object_id) WHERE 1=1 AND wp_postmeta.meta_key = ...


0

Figured this out. 'order' => 'ASC' (or DESC - however you'd like) and 'orderby' => 'menu_order' solves this.


1

If we use: $args = array( 'post_type' => 'custom_post_type', 'post_status' => 'publish', 'posts_per_page' => 9, 'meta_key' => 'pkg_id', 'orderby' => array( 'pkg_id' => 'ASC', 'rand' => 'DESC' ) ); then we get the order part as: ORDER BY wp_postmeta.meta_value ASC, RAND() DESC This seems to ...


5

There is no need to do an overrated amount of queries to accomplish this. you can still use only one query, the_posts filter and some PHP to sort your code as needed. I take that this is a custom query from what I read in your question, so we can do the following: First, we want to introduce a custom WP_Query parameter so that we can use that parameter ...


1

Not possible with a single query you would have to do 3 seperate query each one targeting the different "Package ID's" and ordering those queries as rand. $args1 = array( 'post_type' => 'custom_post_type', 'orderby' => 'rand', 'meta_query' => array( array( 'key' => 'pkg_id', 'value' => 1, // you ...


2

For reference, before: 45q, after: 42q The code is very similar to the code used by @birgire function _tomjn_home_cancel_query( $query, \WP_Query $q ) { if ( !$q->is_admin() && !$q->is_feed() && $q->is_home() && $q->is_main_query() ) { $query = false; $q->set( 'fields', 'ids' ); } return ...


4

Skimming through the WP_Query we find this part of interest: if ( !$q['suppress_filters'] ) { /** * Filter the completed SQL query before sending. * * @since 2.0.0 * * @param array $request The complete SQL query. * @param WP_Query &$this The WP_Query instance (passed by reference). */ $this->request ...


2

Here is a neat trick I learned from @birgire, we can halt the main query by appending AND where 0=1 to the WHERE clause of the SQL query. This might still result in one db query, but it will surely stop the main query from querying posts add_filter( 'posts_where', function ( $where, \WP_Query $q ) { if ( $q->is_home() && ...


0

You can order posts by meta value check out the codex https://codex.wordpress.org/Class_Reference/WP_Query


0

I noticed that the problem was related that one custom field was a taxonomy, so, as I was using the archive page for that custom post type, I only needed to filter the query looking for the date limits. $fecha_actual = current_time('Ymt'); //t regresa el ultimo día del mes $fecha_anterior = date('Ymd', strtotime("first day of last month")); ...



Top 50 recent answers are included