Tag Info

New answers tagged

1

Your AJAX callback method should be outputting something followed by a die() statement. function wp_insert() { ..your code echo $whatever_your_results_are; // die(); } I would also recommend against prefixing your custom methods with wp_. That should be reserved for WordPress and will cause confusion to other developers - and probably you ...


1

This is untested, but I believe if you set type in your meta query to numeric, that will cast the values as numbers so orderby meta_value should work correctly.


0

After poking around for a day and half, I found a solution. There was nothing in my theme that was controlling the search result besides the form actions, which were: <!-- Search Result Page --> <form action="<?php echo home_url('/');?>" method="get" data-javo-patch-form-for-result> <input type="hidden" name="post_type" ...


0

It might be not your case but if behind the scene permalink settings have been switched from default one, then the request: ?category_name=slug1+slug2 is rewritten to /category/slug1/ or /category/slug2/ so only the posts from one category are shown.


-1

if ajax returns zero, the function bound is not registered properly have a read: http://arresteddeveloper.net/woocommerce-get-variation-description-variation-select-changes/ this might point you in the right direction


1

Two options. The first will keep you away from custom SQL, and should be a lot more efficient than what you currently have. It runs two queries, one to get the user ID with the highest hourly rate, and then again to get the lowest. You need one more query to update the user meta cache & then you're home free: $query = new WP_User_Query; $users = array( ...


3

Query results for posts, terms, and metadata get placed in cache. If a function is called that accesses data from previously queried objects within the same request (or you're using a persistent cache mechanism that maintains data across requests), it will not trigger another query and will instead fetch the data from cache.


2

It seems like yes it depends whether it does create a new query or not. As Milo has pointed out in his answer, WordPress using a caching system. The function stack looks like this: get_the_permlink() calls get_permalink() calls get_post() which when given a post ID does this: $_post = WP_Post::get_instance( $post ); which looks like: /** * Retrieve ...


1

The following code will properly store data in wp_fafa: $wpdb->insert( $wpdb->prefix . 'fafa', array( 'title' => trim($row->item(0)->nodeValue), 'liveprice' => trim($row->item(2)->nodeValue), 'changing' => trim($row->item(4)->nodeValue), 'lowest' => ...


1

Make sure you have declared the $wpdb variable global $wpdb;. Also calling $wpdb->query() will execute the query for you, so no need to do it again. I would also recommend using $wpdb->insert() as this escapes your data for you: global $wpdb; $wpdb->insert( $wpdb->prefix . 'fafa', array( 'titile' => trim( ...


1

I figured it out: $the_query = new WP_Query(array( "numberposts" => -1, "post_type" => "plays_events", "meta_query" => array( array( "key" => "show_times_%_date", "value" => $this_month . "[0-9]{2}", "compare" => "REGEXP" ) ), ));


0

I believe all you need to do here is remove the day from your $this_month parameter and use the LIKE comparison (with a trailing %) to query the value - $this_month = date("Ym"); $the_query = new WP_Query(array( "numberposts" => -1, "post_type" => "plays_events", "meta_query" => array( array( "key" => ...


0

I know this has been answered and since your question was based off on using WP_Query, my answer is probably a long-shot but you could also try to use this: wp_count_posts( $type, $perm ); where $type = post_type (post, page, 'custom-post-type-slug') and where $perm = To include private posts readable by the current user, set to 'readable' I've used ...


0

If that is the error, a couple of things could be going on. The part that uses 'require', 'require_once' and 'include' is not likely correct in the code. Each of these code statements should end with a semi-colon [;] not a comma [,] hh3_ I expect is the table prefix initially used in your database. Is that still the prefix of all the tables?? Vee


1

Give this a try. It replaces query_posts(), which you should never use (it kills unicorns) with WP_Query. Basically it first queries your sticky posts and then, if there were less than your required 3 posts, it will perform another query for the relavent number of posts. /** Grab the sticky post ID's */ $sticky = get_option('sticky_posts'); /** Query the ...


5

There is no build in function to achieve what you want, at least not for complicated meta queries like this. If you need to use build in functions for this, the best will be to make use of WP_Query. To make the query faster and to skip the unwanted returned array of WP_Post properties, and because you are only interested in post count, you can use the ...


0

Try using one of the WP User Query Order By Parameters 'orderby' => 'nicename',


2

The solution: $query = array( 'post_status' => 'publish', 'post_type' => 'product', 'posts_per_page' => 10, 'meta_query' => array( 'key' => '_price', 'value' => array(50, 100), 'compare' => 'BETWEEN', 'type' => 'NUMERIC' ), ); $wpquery = WP_Query($query); // return 10 products ...


0

Maybe I don't understand the question either, because the answer is obvious to me. I assume this is for one post, so you'd have 2 custom fields, foo and bar. So in code... $foo = get_field('foo'); $bar = get_field('bar'); if ($foo > $bar) { echo 'foo is greater than bar'; } else { echo 'bar is greater than foo'; }


1

You want to orderby 'date' not by 'meta_value_num' because it is to order numerically. So if you were ordering items by their price, then you would want to use 'meta_value_num'. The meta_key 'news_date' is most likely in date format. You should also cast the meta_value to DATE using 'meta_type' => 'DATE'. $args = array( 'post_type' => 'news', ...


1

This is actually a tricky question, as by stating exact there are two ways in which one can interprit your question - Only find posts where the whole title or the whole content match exactly. For example, if you search My post is super you would not have returned a post with the title My post is super awesome. Fine posts where the exact phrase exists, not ...


0

I think someone else has answered this before: Check this answer, from @Sunyatasattva But apparently WP_Query supports some extra search parameters: 's' => $s, //(string) - Passes along the query string variable from a search. 'exact' => true, //(bool) - flag to make it only match whole ...


0

Try to use child_of at your second foreach, see the documentation. child_of (integer) Get all descendents of this term. Default is 0. Note: the difference between child_of and parent is that where parent only gets direct children of the parent term (ie: 1 level down), child_of gets all descendants (as many levels as are available) So in your case ...


1

You're close. Your first attempt is using get_the_tags incorrectly. The function accepts the post ID you want to get the tags from. In your example, there is no $tag global, so $tag->name is trying to fetch a property of a non-object. In your second attempt, a single post won't have any tag-related query vars, that would only be set on a tag archive page ...


0

Okay thanks for all the helpful comments. It turns out there is no way to do this using WP_QUERY alone. The best way I can think of is to do it is like so: $taxIds = get_terms($options['post-types'][$this->current_post_type->name], array( 'fields' => 'ids', )); $uncategorisedQuery = new WP_Query( ...



Top 50 recent answers are included