Tag Info

New answers tagged

0

thanks for responses, Allowed me to find correct answer which I've posted below - $tickets_for_user = get_posts(array( 'post_type' => 'ticket', 'orderby' => 'meta_value_num', 'meta_key' => 'event_date', ...


2

What you are experiencing is quite normal and expected. This is one of the big reasons I always hammer on this point, never use custom queries to replace the main query on the home page or any type of archive page. They solve one issue but creates plenty other new ones Lets look at what you have and why you are getting these results: BASICS Although you ...


1

In your wp_query loop you'll want to check the page template of the current post object. You'll be able to set that to a string and use it however you want Close to this: while ( $query->have_posts() ) : $query->the_post(); if (is_page) { $pageTemplate = get_page_template(); echo "<p class=\"" . $pageTemplate . "\">" . get_the_title() . ...


4

Try to run your query with "suppress_filters" => true WP_Query allows for posts to be added after the query has run. found_posts is the actual queried amount of posts, post_count is updated after running the filters. If this fixes it search your code (Any active code, check network activated plugins as well) for the_posts or posts_results filter and ...


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


0

pre_get_posts() is not a normal filter. It's an action filter that happens after all arguments have been passed to any single query of your WordPress and before the queries are run against the db. All you can should do inside pre_get_posts() is modify query parameters if WP conditionals are met (not all conditionals are available, just the ones that are ...


0

As Milo noted, you should just edit the query. Your problem is that you are then executing it and processing it while the pre_get_posts filter is processing. Being a filter, pre_get_posts should be used to modify the query. It will then be ran and then your page will be displayed. So: function cv_testimonials_list($query) { if ...


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.


0

Your issue currently is that pre_get_posts fires for every query within a request. You're creating an infinite loop which terminates with a fatal out of memory error. If you enable debugging, you should see the error message. Your testimonials_list function fires for the first query on your page, and the condition is_page('9595') is met, and you create a ...


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


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


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


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


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.


0

Yes, I think the only way is (See Andrei Gheorghiu's answer) If you choose to remake the loop, the slightly tricky bit is to make the $args array the same as get_posts()'s defaults: $args = array( 'post_type' => 'event', 'posts_per_page' => 6, 'post_status' => 'publish', // If post_type 'attachment' then 'post_status' => 'inherit' ...


0

Old question but, I wanted to post this here for reference, since I never accepted an answer. This functionality is now easily achieved using the Jetpack centralized dashboard. You can administer updates to all your connected WP sites. http://jetpack.me/2014/12/16/jetpack-3-3-a-single-home-for-all-your-wordpress-sites/


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 ?


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.


-3

**The default syntax for showposts is-** <?php $query = new WP_Query (array( 'showposts' => 5, ) ); while ($query->have_posts()): $query->the_post(); ?> <li> <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> ...


0

I modify wordpress query from functions.php: //for "IS_PAGE" conditions, pre_get_posts doesnt work (it's WORDPRESS behaviour) //so, inside `add_action('wp....` use `add_filter(posts_where.....` OR modify "PAGE" query directly into template file add_action('pre_get_posts','myf88');function myf88($query) { if ( !is_admin() && ...


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


0

After reading a bunch of tips for running a WP_Query filtering by serialized arrays, here's how I finally did it: by creating an array of comma separated values using implode in conjunction with a $wpdb custom SQL query utilizing FIND_IN_SET to search the comma separated list for the requested value. (this is similar to Tomas's answer, but its a bit less ...


0

Sounds like you're looking for the NOT IN value of the operator argument of a tax_query. Depending on your situation, you should use either WP_Query or pre_get_posts. Your tax_query would then look something like this: 'tax_query' => array( array( 'taxonomy' => '{your taxonomy slug}', 'field' => 'slug', 'terms' => ...


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


0

For testing purposes in your functions.php file, try this - add_action('init', 'my_test_get_all_bands', 99); function my_test_get_all_bands(){ echo '<pre>'; print_r(get_all_bands()); echo '<pre>'; } As I was attempting to say in my comment to your question (and as Pieter Goosen explained rather better), if your taxonomies have not yet been ...


1

In both your queries you are doing it wrong. You are running a separate instance of WP_Query for every argument set $args = array( 'posts_per_page' => $count, // Limit count ); $query = new WP_Query( 'cat=1' ); $query = new WP_Query( $args ); Should be $args = array( 'posts_per_page' => $count, 'cat' => 1 ); $query = new WP_Query( $args );


1

@Musa how can we put multiple order value for the fields? I was wondering the same question and I found this : In 4.0, you can now pass an array to WP_Query as the value for orderby. The syntax looks like: $q = new WP_Query( array( 'orderby' => array( 'title' => 'DESC', 'menu_order' => 'ASC' ) ) ); Have a look where for more details : ...


1

Don't nullify the main query, this breaks stuff. Also, avoid using the $wp_query global as a custom variable. This breaks the main query and causes issues. You can also try adding 'suppress_filters' => true, to your arguments to suppress any custom filters if you are using any custom filters. Also, don't use TEMPLATEPATH, it is due to be depreciated ...


0

You have a couple of issues here looking at your code and tags used to tag your question show_posts is wrong. It is depreciated in favor of posts_per_page. Also, it should be showposts. You cannot use showposts and posts_per_page together. You should only use posts_per_page Don't use camelcase in you custom post type names, they are really problematic when ...


2

You could use the current_post property and the rewind_posts() method of the WP_Query class, to target the relevant post objects. You could try playing with the following example (untested): if( $testimonials->post_count >= 3 ) { // First post: $nr = 1; if( isset( $testimonials->posts[$nr-1] ) ) { ...


3

Make use of an offset to skip the first 2 posts if you need the third post only, and then set you posts_per_page to 1 to get only that specific post You can try something like this in your arguments $args = array( 'post_type' => 'testimonial', 'offset' => 2, 'posts_per_page' => 1 ); $testimonials = new WP_Query( $args ); while( ...


1

Try: <?php if ( $the_query->have_posts() ) :?> <?php echo '<h3>' . date('l, F jS') . '</h3>'; ?> <?php while ( $the_query->have_posts() ) : ?> // etc.


0

From the url you supplied it looks like you are using a custom post type of blog. The most likely reasons you are not seeing the post you want to display is that by default WP_Query is only set to display posts - see WordPress Codex on WP_Query Post & Page Parameters for more info. So for your WP_Query to return the post you are after you will need to ...


0

In general this would make sense at pre_get_posts since you could just express conditions as meta query and let WP figure out SQL. In your specific case this won't work, since that format is horrible for programmatic comparison. Unless you can change format to something more friendly, you will probably have to write some pretty custom SQL to make it work.


1

What else can I do to the query to do as little work as possible to eliminate "extra" posts in PHP that get queried because my query is too broad. The trouble is, meta queries are slow. Metadata is a simple key => value type database. Keys are indexed, and values are longtext. That's it. No datatypes. No additional indexes. Nothing. And not to mention ...


1

It is terms (plural) not term (singular) in tax query arguments. :)


0

I guess you have 4 different news, you want display first news use large image of each page and the news of large image is different others, right? If you right, the following code, maybe work for you. <?php $b=1; $args = array( 'tax_query' => array( array( 'taxonomy' => 'gens', 'field' => 'slug', ...


0

I don't know why have you put $b%4==1 condition. You can simply check for $b==1.And one more thing I would suggest is to use if and else both.So code would be something like this: <?php $b=1; $args = array( 'tax_query' => array( array( 'taxonomy' => 'gens', 'field' => 'slug', ...


1

Does this work? global $post; // make sure the post object is available $slug = $post->post_name; // get the slug // insert the slug into your query $args = array( 'post_type' => 'client_prop', 'posts_per_page' => 10, 'tax_query' => array( array( 'taxonomy' => 'prop_neighborhood', 'field' => 'slug', 'terms' => ...


0

the_posts_navigation() is simply a wrapper function for get_the_posts_navigation() which issimply a wrapper function for paginate_links. The first two functions uses the the same exact parameters that is being used by paginate_links and actually passes it to the latter function as well get_the_posts_navigation() and the_posts_navigation() is good new ...


0

You could use the is_main_query Function : http://codex.wordpress.org/Function_Reference/is_main_query Happy Coding, Kuchenundkakao


0

This function uses the get_the_posts_pagination() which uses the GLOBAL wp_query to setup the paginate_links() function, so I believe that doesn't work for get_posts. https://developer.wordpress.org/reference/functions/get_the_posts_pagination/ Try use the function paginate_links() by itself or the function posts_nav_link() PS: Make sure you use ...


0

The quick and simple method might be to create a custom page template and have the search form send the user to the page that you create with it. <?php /* Template Name: Location Results */ if ( isset($_REQUEST['search_field_name']) && !empty($_REQUEST['search_field_name']) ) { # Read and escape the input data # Do your query, grab your ...


1

First off, I'd like to note a few things wrong with your Post Type and Taxonomy set up. There's a few settings in your $labels that don't make sense: $labels = array( ... 'post_type' => 'attachment', 'post_parent' => $post->ID, 'post_status' => 'inherit', 'post_mime_type' => 'image', ); These last 4 options ...


0

Problem solved, I've used this: $d=new WP_Query( array( 'category__in' => array(4), 'post_type' => 'post', 'posts_per_page' => '-1', 'orderby' => 'meta_value', 'order' => 'ASC', 'meta_query' => array( 'relation' => 'AND', array( 'key' => ...


0

Firstly, your problem with the last post type and/or term overwriting all previous is because 'filter' is a 2-dimensional array. Therefore 'taxonomy' (the key in this case) can only have one value. If that seems odd, read this super helpful page on the plugin's github that helped me a lot (read this) tldr; term lists and multi-dimensional arrays are ...


-1

I formed this query based on this answer. I would appear this is no longer the way to do it... I reformatted the query to look like this: query_posts( array( 'post_type' => 'events', 'showposts' => -1, 'order' => 'ASC', 'orderby' => 'meta_value_num', 'meta_query' => array( ...


0

A sneaky way to do it using MySQL, assuming the number's always at the end, is to reverse the title, convert it to a number (+0), and then reverse again and convert it to a number: function wpse174646_posts_orderby( $orderby, $query ) { if ( $query->get( 'orderby' ) != 'title_number' ) return $orderby; global $wpdb; return ...


0

PHP has a sort_natural flag on its sort() function (MySQL doesn't). So if you built them into an array before displaying them, you could sort it that way. Something like: $teams = array( 'Team E1', 'Team E10', 'Team E2', 'Team E11', ); sort($teams, SORT_NATURAL); print_r($teams); Will output: Array ( [0] => Team E1 [1] ...


0

You can access the current post ID within the loop via get_the_ID() while ( $secondary_loop->have_posts() ) : $secondary_loop->the_post(); rating( get_the_ID() ); endwhile; wp_reset_postdata();



Top 50 recent answers are included