New answers tagged

0

My guess is that you're accessing $response as an array when it's a \WP_Error. Check out the possible return values of wp_remote_post: (array|WP_Error) The response or WP_Error on failure. You should modify your code in a couple of ways: $response = wp_remote_post( $remote_url, $request ); if ( is_wp_error( $response ) ) { // handle the error response ...


0

Adding 'post_status' => array('publish', 'future') to your $args will show only future published posts. $args = array( 'post_type' => 'event', 'meta_key' => 'event_start_date', 'orderby' => 'meta_value', 'order' => 'ASC', 'post_status' => array('publish', 'future') ); get_posts( $args );


1

No. You could try to remove year from the whitelist of query variables, but this would cripple date archives, break all date based filtering in WP Admin, as well as break any plugins or themes that rely on this functionality. This doesn't just impact user interface, but any date based query internally E.g. sitemaps in core would break, year based RSS and ...


0

I found a problem. I had to change this: $args = array( 'cat' => $category->name, 'posts_per_page' => 3,); for this: $args = array( 'category_name' => $category->name, 'posts_per_page' => 3,); In first code I was passing category name which is string to argument expecting ID of category. Here is Codex reference where I ...


0

If someone has problems with displaying more than 5 results, here's a small tweak. $documents = get_posts(array( 'post_type' => 'document', 'posts_per_page' => -1, //add this line


0

Try $PostID = get_the_ID(); the_field('text_field', $PostID);


0

After some time with WPML support and with some debugging/digging in the theme's core files, I found where the breadcrumb was created. I pointed this out in the support and to also add the taxonomy on pages also in their filtered queries. I was using default WordPress queries and I was aware that taxonomies on pages are not the default use in WordPress. Also,...


0

Though OP asked specifically for a wp_query, this also works: get_pages('child_of='.$post->ID.'&sort_column=menu_order');


1

I'm guessing it's because you used order_by when it should actually be orderby - that order_by wasn't just a typo in the question, right? And also, if the meta value is a date, then you should also set the meta_type parameter to DATE so that the sorting works as expected. So try with: $the_query = new WP_Query( array( 'post_type' => 'event', '...


1

It didn't work because your tax query is missing the operator which should be set to NOT IN. So just add it like so: 'tax_query' => array( array( 'taxonomy' => 'post_format', 'field' => 'slug', 'terms' => array( 'post-format-' . $post_format ), 'operator' => 'NOT IN', ) ), And please, avoid using ...


0

There are ways to loop through all the sites in a multisite, then do a "WP Loop" on each sub-site. It can get a bit complex, but it can be done. I did some research on this, and found some code fragments that would do it, but no full-on solution. So I wrote my own plugin (called "Multisite Post Reader", available in the repository) that ...


0

Replace $args = array( 'post_type' => array('product', 'product_variation'), 'post_status' => 'publish', 'posts_per_page' => get_option('posts_per_page'), 'paged' => $paged, 'tax_query' => $tax_query, 'orderby' =&...


0

As I said in the comments, if you want 5 (or a specific) number of posts per category, then you need to make multiple WP_Query calls. Otherwise, you could use something like new WP_Query( [ 'cat' => '1,2,3,4' ] ) and then group the returned posts by their category upon displaying the posts. Working Examples Revised so that categories without any posts do ...


1

You can do is to create an additional user and switch to it in order to use the wp-cli


0

Thanks for the response. Managed to find what the cause was. Its caused because of sticky feature, my posts was not sorted accordingly. So, can anyone suggest me how do I remove saved sticky feature field from the database? Any help would be much appreciated!


0

What you're trying to do — using the OR relation with the tax_query and meta_query parameters, i.e. to have a <tax queries> OR <meta queries> instead of <tax queries> AND <meta queries> command in SQL, unfortunately (without custom and possibly complex queries) is not possible in WP_Query for now, therefore that 'relation' => 'OR' ...


1

$sticky = get_option( 'sticky_posts' ); $args = array( 'post_type' => 'post' , 'orderby' => 'date' , 'order' => 'DESC' , 'posts_per_page' => 4, 'cat' => '3', 'paged' => get_query_var('paged'), 'post__in' => isset( $sticky[0] ) ? $sticky[0] : ...


1

It's actually pretty simple: You'll want to use an OR relation, and use the NOT EXISTS operator for selecting posts that are not assigned to any terms in the specified taxonomy. $tax_query[] = array( 'relation' => 'OR', array( 'taxonomy' => 'location', 'field' => 'name', 'terms' => $location, ), array(...


0

I think is as simple as using Timber's Timber::get_posts() instead of the WP_Query class: $context['testimonials'] = Timber::get_posts( ['post_type' => 'what_our_clients_say', 'posts_per_page' => 2] ); Timber::render('whatever.twig, $context); ... from there you can loop through the testimonials and access ACF values via meta: {% for post in ...


1

Your query args contains a nested array, so it won't work that way — the items like posts_per_page belongs in the main array (e.g. new WP_Query( array( 'posts_per_page' => 5 ) )). So it should be like this: Note that the 'category' => 'art' won't work. Instead, use the category_name parameter to query posts by the category slug. $query1 = new WP_Query( ...


1

It seems that the format I used for $argsar needs to be changed to $argsar = array ( 'post_type' => 'auctionroom', 'meta_query' => array( array( 'key' => 'auctionroom_username', 'compare' => '=', 'value' => $auctionroomname ...


1

It doesn't work with add_rewrite_rule() because of the ?view= part in the URL (it's the first parameter for the function) — i.e. WordPress strips that query string part, hence it's not included when WordPress finds a matching rewrite rule. how I can remove ?view=12a34b56 after set post name You can't (not on the same page), because that is a query string ...


0

Some debugging steps that might help So this may not exactly answer the question, but your code is good and you also said it worked (perfectly) fine on the staging site, so this is likely a plugin issue or a custom code in the active theme, whereby the plugin/code is overriding your posts_per_page setting via the pre_get_posts hook or a similar one (for ...


Top 50 recent answers are included