Tag Info

New answers tagged

0

You are actually not that far away with pre_get_posts, you just need to first grab the current post types that are in the query before adding your own. Also, I'd recommend using a $priority of 99 so that the action is hooked after any other pre_get_posts hooks, meaning that if users add there own CPT's (or built in post types) they are detected and included ...


1

You have missed meta_value parameter. You can use like this : $today=date('Y-m-d'); $args = array( 'numberposts' => 10, 'post_type' => 'events', 'meta_key' => 'event_date', 'meta_value >=' => $today ); // get results $the_query = new WP_Query( $args );


0

Use this for pagination <?php $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1; $mostpopular_args=array( 'post_type' => 'post', 'orderby' => 'meta_value_num', 'meta_key' => 'view_count', 'paged' => $paged, 'posts_per_page' => '10', ...


1

You might be able to use the query filter hook See this WPSE answer Basically, you can do something like: add_filter( 'query', 'your_filter_function' ); function your_filter_function($query_sql) { // do something to $query_sql return $query_sql; } This will get called for every query, so you'll need to test $query_sql to make sure it's the ...


0

Fortunately, this complicated database query is no longer needed. WordPress 4.1 added the ability to make complex nested meta queries which is exactly the thing I was trying to accomplish. Here is the Trac ticket with the feature: https://core.trac.wordpress.org/ticket/29642


0

'meta_value_num' - Order by numeric meta value (available with Version 2.8). Also note that a 'meta_key=keyname' must also be present in the query. This value allows for numerical sorting as noted above in 'meta_value'. Try to use like this : $args = array ( 'post_type' => 'product', 'post__in' => $post_ids, ...


0

You don't need meta_query in your code. And also you don't need to check numeric value of meta field like that. To sort by numeric value, in your orderby parameter, you should use meta_value_num instead. So this will be your WP_Query. $args = array ( 'post_type' => 'product', 'post__in' => $post_ids, 'posts_per_page' => -1, 'order' ...


-1

You Can Display you custom post type using this method your pagination can work !!! <?php query_posts( array( 'post_type' => 'post', 'posts_per_page' => '2', 'paged' => get_query_var( 'paged' ) ) ); if (have_posts() ) : while (have_posts() ) : the_post(); ?> <!-- Start your post. Below an example: --> <div ...


1

You could do something like this to simplify it. IF We're in this loop we're either going to have both a left AND right column OR at least a left column, if we have less than 4 posts, so we can move a container div outside the main conditional: if ( $td_query->have_posts() ) { while ( $td_query->have_posts() ) { $td_query->the_post(); ...


0

In the posted code the variable $item is still being used but undefined now - also within the relationship query you can use standard WP calls like the_permalink() and the_title() without needing to echo.


6

I've never seen it done before but the logic of the PHP IF/ELSE should mean you could simply plug a new query in after the ELSE: if ( have_posts() ) : while ( have_posts() ) : the_post(); get_template_part ( 'templates/post', 'main' ); endwhile; else: $the_query = new WP_Query( $args ); if ( $the_query->have_posts() ) : while ( ...


0

See the posts_per_page query var. add_action( 'pre_get_posts', 'add_tours_post_type_to_query' ); function add_tours_post_type_to_query( $query ) { if ( is_home() && $query->is_main_query() ) { $query->set( 'post_type', array( 'tours' ) ); $query->set( 'posts_per_page', 2 ); } return $query; }


1

This should do the trick: add_action( 'pre_get_posts', 'add_tours_post_type_to_query' ); function add_tours_post_type_to_query( $query ) { if ( is_home() && $query->is_main_query() ){ $query->set( 'post_type', array( 'tours' ) ); $query->set( 'posts_per_page', 1 ); } return $query; } For the future the Codex can be your ...


1

You have a couple of flaws in your code get_post_meta( 'fap_referral_link' ) should be get_post_meta( $post->ID, 'fap_referral_link', true ). Please see get_post_meta() You should always first check if you actually have posts before you run your foreach loop Never ever use extract(). It uses eval() which stand for EVIL. This has been completely removed ...


0

The final working arguments: <?php if( isset( $_GET['Price'] ) ) { $meta_array[] = array( 'key' => 'price', 'value' => esc_attr($_GET['Price']) // 'compare' => '=' ); } if( isset( $_GET['Region'] ) ) { $meta_array[] = array( ...



Top 50 recent answers are included