Tag Info

New answers tagged

1

The correct query is: $args1 = array( 'showposts' => 5, 'ignore_sticky_posts' => 1, //ORDER ARGUMENTS 'meta_key' => 'post_views_count', 'orderby' => 'meta_key_num', 'order' => 'DESC', //META QUERY 'meta_query' => array( array( 'key' ...


1

You cannot sort inside a meta_query. The sorting parameters are invalid inside the meta_query. You will need to move the sorting parameters to outside the meta_query and remember to set the meta_key which will be used for sorting References: WP_Query Custom Field Parameters WP_Query Order and Orderby Parameters


0

I'm not sure how you set up looks, but it does seem that you have a lot of taxonomies registered to your post type, so I don't think it will be very viable to use the the exclude parameter in get_terms() to exclude the specific term. What I would suggest is, inside your foreach loop before you declare your query arguments, add the following line if ( ...


2

Try to change: <?php if ( have_posts() ) To <?php if ( $verhuurd_query->have_posts() )


1

The function have_posts is for the main loop, so the if statement is checking the main loop, which will probably always have posts. You want to use the custom query's have_posts for the if statement instead. if ( $verhuurd_query->have_posts() ) : while ( $verhuurd_query->have_posts() ) : $verhuurd_query->the_post(); ?>


1

As already pointed out in comments gb_bypass_filter is not a valid parameter for WP_Query. If you want to suppress to effect of filters on your query, add 'suppress_filters' => true to your query arguments previous_posts_link() does not accept two arguments, only one. Unlike next_posts_link(), it does not have the second $max_pages parameter. So you can ...


-1

The previous_posts_link and next_posts_link functions are for archive page pagination, they both check if is_single is not true, so will not work on any sort of single post, page, or custom post type. You need to use paginate_links instead: http://codex.wordpress.org/Function_Reference/paginate_links


1

You're not using query_vars quite right - this filter is for whitelisting "public" query vars, not actually setting their values. It's also called rather early (wp::parse_request), so any conditional tags like is_tax() will always be false at this stage. Use the pre_get_posts action for overriding the default query. Having said that, you need a custom ORDER ...


0

hope this will usefull to some one. <?php /* ADDED by for sorting ASCENDING order but call for price (ie price with 0) last */ function my_sort_custom( $orderby, $query ){ global $wpdb; $orderby = " case when CAST(meta_value AS SIGNED) = '0' then 1 else 0 end ,CAST(meta_value AS SIGNED) "; return $orderby; } ...


0

Just one notification... this query is work for me also.. but if you use sticky post.. do not forget to add 'ignore_sticky_posts' => 1, and also you forget to add while - endwhile ... this was issues with my query ... so the "the main query" will be // the main query $query = new WP_Query(array( 'post_type' => 'any', 'post__in' => $post_ids, ...


0

If you are using this inside the loop of your WP_Query then why are you providing the Post ID parameter in functions. You don't need to do that. So your code will become this. <?php echo '<h2><a href="' . get_permalink() . '">' . get_the_title() . '</a></h2>' . get_the_post_thumbnail( 'full' ); ?> And please read the answer ...


0

The very thing I tried to accomplish appear not to be complex at all. SQL Code: SELECT * FROM wp_posts WHERE post_type = "event" AND post_status IN ("publish", "future") AND post_date > "2015-02-26" AND post_parent != 0 GROUP BY post_parent ORDER BY post_date ASC; There were two ways I could do this. I am using the second ...


0

One of the options would be to sort at a database level by a dynamically calculated column. This is too complex for me. Having your task on production I would probably create a third meta key: 'division' derivated from the two and update its value on every post save. Then I would sort by this key in WP_Query(). Third option for small amount of posts would ...


1

Assuming your date is in the correct format for proper ordering (yyyy-mm-dd), add a meta_query to your args: $args = array( 'post_type' => array('basic_events'), 'order' => 'ASC', 'orderby' => 'meta_value_num', 'meta_key' => 'date_of_event', 'paged' => $paged, 'meta_query' => array( array( ...


0

Try this: $yoursearchquery = 'This is my search'; $users = new WP_User_Query(array( 'search' => $yoursearchquery, 'meta_query' => array( 'relation' => 'OR', array( 'key' => 'shoe_size', 'value' => $yoursearchquery, 'compare' => 'LIKE' ), array( 'key' ...


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

You could use "save_post" hook to capture all submit within WP, for ex: function just_got_you( $post_id ) { if ($post_id != '123') return; << do your logging stuff here >> } add_action( 'save_post', 'just_got_you', 10, 2 ); Change 123 to your page/post id. More reference here Save Post Hook


1

After hours of searching and testing I finally came to a solution. This code and SQL shows events with a parent id of 0 and is ordered by the dates of child events. Raw SQL cannot be used to replace the default way WP queries the database but there are always some kind of workaround that can be used. The PHP Code: <?php function ...


0

Here is a solution I also used in the past. This allowed me to use the slides in other places on the page as well as in tiled galleries or thumbnails and so on. <?php $indicators = array(); $slides = array(); $counter = 0; while ( $loop->have_posts() ) : $counter++; array_push($indicators, '<li data-target="#testimonials" ...


1

You can use the condition <?php if($loop->post_count > 1){ /** * so show the carousel counter */ } ?>


1

Firstly, the_post() doesn't actually output anything - it just sets up the post data ready to output. You'll need to do something like this to show the posts: <?php while ( $loop->have_posts() ) : $loop->the_post(); the_title(); the_content(); endwhile; ?> There's several more tags you can use and you'll want to format the HTML ...


1

If you don't define the field in the array then it defaults to ID. Your options are term_id, name and slug: http://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters 'tax_query' => array( array( 'taxonomy' => 'language', 'field' => 'name', 'terms' => get_the_title() ) )


0

I think you only have to change '0', that is a string, by simply 0, that is a integer corresponding to the first place of the array of posts. I thik this is a good idea, maybe WordPress should do it by default ^^


0

On volume pass single quote in parameter. Now your query is SELECT * FROM cp WHERE year = '1911' AND quarter = '4' AND volume = '2a' AND page <= '1475' ORDER BY page DESC LIMIT 1 Try this code


1

You are stomping on the global wordpress posts with your plugin. Doing your wp_query call and then calling $recent_articles_wtb->the_post(); means that later (after your loop), you will want to call wp_reset_postdata(); # Thanks Milo That should reset the global $current_post and $post objects.


3

Note that the relation part in the meta_query argument, is only used to define the relation between the sub meta queries. You can try this setup: $args = [ '_meta_or_title' => $thesearch, // Our new custom argument! 'meta_query' => [ [ 'key' => 'model_name', 'value' => $thesearch, ...


1

You right Bruno, the AND is optional, I tried without it and it is now working, not sure why, here is the code : function GetBrandChildren() { $output = ''; //retrieve POST data sent by AJAX $parent_id = $_GET['parent_id']; //Define query arguments $args = array( 'post_type' => 'aromes-type', 'meta_query' => array( ...


0

From the Codex for pre_get_posts: pre_get_posts cannot be used to alter the query for Page requests (page templates) because 'is_page', 'is_singular', 'pagename' and other properties (depending if pretty permalinks are used) are already set by the parse_query() method. See: Query Overview. The recommended way to alter the main query for page requests is ...


0

@Aaron, here is an alternate version of your solution, including sorting: function search_pre_get_posts( $query ) { if ( $query->is_search() && $query->is_main_query() ) { $currentdate = current_time('Ymd'); $query->set( 'meta_query', array( 'relation' => 'OR', ...


0

Ok, @guiniveretoo nailed it, with a couple edits: Ok, @guiniveretoo, you nailed it! With a couple tweaks, this is what I used and it works: function search_pre_get_posts( $query ) { global $wp_query; if ( is_search() && $query->is_main_query() ) { $currentdate = current_time('Ymd'); $args = array_merge( $wp_query->query_vars, ...


3

You're gonna need regular expressions to accomplish that. First of all, you need to change 'LIKE' to 'RLIKE' (or 'REGEXP'). Second, replace $keyword in 'value' with a regex that involves word boundaries. Like so: $queryArgs = array( 'post_type' => 'faculty', 'posts_per_page' => -1, 'meta_query' => array( 'relation' => ...


0

There is no difference in terms of the "final" query. The former was the "old" way of querying post meta, before WP_Meta_Query was introduced with support for more complex queries. WP_Query::get_posts() now simply translates meta_key/value arguments into the new format with WP_Meta_Query::parse_query_vars(). Use whichever format you feel suits best for the ...


2

The problem you are having is that get_queried_object returns results based on the query that was run. On author.php, the queried object was an author. On single.php, page.php, or any custom post type template, the queried object will be the post, not the author. This means that if you want to use $wp_query->get_queried_object();, you will have to be ...


1

The arguments passed to the WP_Query class's constructor are used to describe the posts you are "looking for" in, and wish to retrieve from the database - the 'meta_query' argument is used to retrieve posts that contain a particular meta key and/or value. In order to actually manipulate (i.e. create/retrieve/update/delete) post meta-data, you should be ...


1

The way you did in your code you are querying posts with the key rw_related_link. If I understood you right, you must use get_post_meta inside the loop. <?php while ($normal_query->have_posts()) { $normal_query->the_post(); $related_link = get_post_meta(get_the_ID(), 'rw_related_link', true); // The value you want is ...


1

As I stated in comments, use pre_get_posts to alter the main query. Never replace the main query with a custom one. Again, from comments Just for starters, on each page load you are running the same query twice, it is slow, double the amount of db calls and pagination has to be tweaked to work almost 100 percent, this just to get the same posts :-) You ...


0

$args = array( 'post_type' => 'works', 'posts_per_page' => 40, 'meta_key' => 'wpcf-composition-date', 'orderby' => 'wpcf-composition-date', 'order' => "DESC", 'offset' => $offset, 'tax_query' => array( 'taxonomy' => 'genre', 'field' => 'slug', 'terms' => ...


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


3

You can pass a space-delimited set of columns to orderby argument of WP Query: $args = array( 'meta_key' => 'wp_ratings', 'orderby' => 'meta_value_num date' ); $query = new WP_Query( $args ); You can also pass an array of key => sort_order for more granular control, for example: $args = array( 'meta_key' => 'wp_ratings', ...


1

As you can see in your custom WP_Query, you pass hardcoded aguments, you are not evaluating the arguments passed in the URL, so they does not affect to the result. In your case, it seems that using a custom query for the archive template is the bad way. When you request the archive template, the events for the archive have been already queried and you are ...


0

A single field would be enough but if you manage your way with 3 that's good as well. I would do a loop through the results and end up with a structure like the following: $years = array( '2015' => array( <WP_Post object>, <WP_Post object>, etc... ), '2016' => array( etc... ) ); Then you ...


0

Try using this: $args = array( 'post_type' => YOUR_POST_TYPE, 'meta_query' => array( array( 'key' => '_wpcf_belongs_marque-type_id', 'value' => $parent_id ) ) ); In your loop set an else statement just to sure that you query isn't returning zero results: if ( ...


1

get_object_vars() returns an associative array of object properties - so queried_object is never in $wpQueryObj, it's a key: $wpQueryObj['queried_object']. Besides, you shouldn't be doing any of that anyway - use get_queried_object(): if ( $wp_query instanceof WP_Query ) { if ( $object = $wp_query->get_queried_object() ) { $query_name = ...


4

Move the control structure outside the template file and just put the repeatable markup and template tags inside. $event_query = new WP_query($args); if( $event_query->have_posts() ){ while( $event_query->have_posts() ){ $event_query->the_post(); get_template_part('loop', 'home'); } } wp_reset_postdata();


0

You never start the main loop: <?php if (have_posts()) : ?> <h1 class="pricing">Prices</h1> <h2><?php the_title(); ?></h2> <?php the_content(); ?> You check if there are posts in the main query, but you never start the loop, and jump straight to showing the title and content, you need to move ...


1

You could add a second array to check if the 'DTEND' value is not set: $args = array_merge( $wp_query->query_vars, array( 'meta_query'=> array( 'relation' => 'OR', array( 'key' => 'DTEND', 'compare' => '>=', ...


0

Thanks karpstrucking, This was a simple case of me needing to understand the Query better. Once I fully understood that wp_query returns a string for the sql query, it was a simply case of doing what I needed to do to correction the event_date value, concatenating on the additional title or meta_num_value and returning that. Then I would just have to ...


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

I had to do this on a project years ago. Similar answer to djb, just with a bit more details. This will output all of your taxonomy names as an h3, with a bulleted list of each post title linked to their detail page. <?php // Output all Taxonomies names with their respective items $terms = get_terms('member_groups'); foreach( $terms as $term ): ?> ...


-1

'query' => $query_array, should be 'meta_query' => $query_array,



Top 50 recent answers are included