Tag Info

Hot answers tagged

3

Ignore my comment about meta_query. Not only does it not work with $query->set(), you wouldn't be able to control the critical "A OR B" requirement of the query. Instead, I believe what you require is possible via a combination of both the pre_get_posts action hook and posts_where filter hook as follows. add_action('pre_get_posts', ...


3

I think instead of using PHP rand you're better off limiting ( if you need to ) using posts_per_page and then getting a random set using orderby => 'rand'. Full List of Ordering Parameters So if I were to edit your query it would look like this: $args = array( 'post_type' => 'attachment', 'meta_key' => 'on_front_page', 'meta_value' ...


2

I guess it should work the way it is described in your question of default code for Advance custom fields Also as custom field are part of post you can use $post->name of custom field also.


2

The main query runs before the template is loaded. WordPress knows what template to load based on the results of that query. If you want to insert an additional query into the content area, either create a shortcode, or add a filter on the_content and do your page check/query output there.


1

All of these cost another DB Query (each!), and worse still since they are in a loop each one happens around 300 times. Don't panic! The posts from your query are stored in WordPress' object cache (which is simply memory, unless you have a custom cache system in place). All functions that operate on posts route through this cache, so in your case ...


1

Isn't that just the regular WP loop? Don't think this is related to ACF, since as you say this distance-thing isn't a custom field and ACF is made for working with those. Not sure how you build this without seeing more code. But couldn't you go something like $post->distance ?


1

You can filter any WP query using pre_get_posts(). The (sometimes) tricky part is that it is run against all queries of WP so you need to pinpoint your query using WP conditionals (is_admin(), is_page(), is_archive(), etc... ). You'll find a few useful examples on that page, too.


1

Milo noted that there is no $wp_query object in wp-admin page, so we can get $paged via: $paged = ( $_GET['paged'] ) ? $_GET['paged'] : 1; Now that we have $paged, we can code our own pagination. I will demonstrate how in its very simplest form. First let's get maximum pagination pages: $max_pages = $the_query->max_num_pages; Then calculate the ...


1

I'm not sure if this is going to solve your whole issue, but you can add the paged parameter to your current custom query. I don't know why you have set the offset parameter. If your offset is 0, omit it completely Also, remember to reset your post data after your custom query. Try something like this as a start and then work from there <?php $paged = ...


1

The below is starting after you do your query: $slide_list = array(); if ( $slides->have_posts() ) { while ( $slides->have_posts() ) { Grab the next slide using next_post to grab it without stomping globals $slide = $slides->next_post(); $slide_id = $slide->ID; Your image title is your post title: $slide_title ...


1

Try: $the_query = new WP_Query( array( 'post_type' => 'Testimonials' ) ); Looks like you probably just need to change that to : $the_query = new WP_Query( array( 'post_type' => 'testimonial' ) ); You need to use the name you created it with when looking at post_type



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