Articles of wp query

pre_get_posts order by not working

I am using the pre_get_posts hook to alter a query before it runs. The posts in question are performances and so are date and time based. I want to alter the query to get all performances which are in the future (i.e. the date is greater than today or the date is today and the […]

Set div columns in a loop by post count

I’m trying to post images from a custom post type into columns based on the amount of posts that are returned in the loop. This is my code: <?php // args $args = array( ‘numberposts’ => -1, ‘post_type’ => ‘sponsor’, ‘meta_key’ => ‘sponsor_headline’, ‘meta_value’ => ‘Partner’ ); // query $the_query = new WP_Query( $args ); […]

Automatic post deletion

I’ve built a system where I have 2 options – lifespawn of draft and lifespawn of published post (integer which marks days). If post is being published, exact date-time of publish is saved as postmeta, also lifespawn is added to that time and that value is saved to database as expiration date-time, same thing with […]

Error : “Cannot use object of type WP_Post as array in”

Fatal error: Cannot use object of type WP_Post as array in C:\xampp\htdocs\wordpress-4.3.1\wp-includes\query.php on line 3716 I don’t know what is this I am searching from internet but not find the solution

wpdb custom post_type problem

I want to use custom post type in my custom SQL query, but, when I add the custom post type im my query, I get no results. Where’s my probelm ? This is the code I’ve tried $top5_ov_performance = $wpdb->get_results(“SELECT post_id,meta_value FROM “.$wpdb->prefix.”postmeta WHERE meta_key = ‘sd_top5_overclocing’ AND (post_type = ‘cpu’) ORDER BY meta_value DESC […]

query multiple taxonomies

I have a function set up to show ‘Similar Products’, i.e. showing products that share the same products-category taxonomy term. This works great but I want to narrow the function even further and make it more specific. Thus I want it to look at 2 taxonomies (product-category and space) to find similar products. The current […]

Rewrite rule to prettify two $_GET variables while in a new endpoint from a page

I’m trying to create a permalink rule which is a few levels deep. I have a basic page /page-slug/ – I’m appending to it a new endpoint: /page-slug/my-endpoint/ – from here I need to nest one id and one string that contain $_GET variables, such as /page-slug/my-endpoint/?some_id=123&some_string=string which should become: /page-slug/my-endpoint/123/string/ I got all the […]

How can i skip same post from taxonomy term?

I’m trying to retrieve the posts of specific taxonomy categories. I have two taxonomy categories. Category One Category Two In these two have some different and same posts. So when i retrieve the data through terms id then query return some post two times, because these posts are link from above two categories. $ourwork_cat_ids = […]

wp_delete_post deletes all posts instead of just expired ones

I am trying to set up a cron job which deletes posts which have past their expiry date (i.e expiry date < today’s date). I have a meta box on the custom post type which adds an expiry date to the post. I have set up the cron job to trigger the wp_delete_post every hour. […]

if wp_query taxonomy term have posts

Having formulated my $query for a custom taxonomy on a page template, how would I ask if a specific term has posts? $args = array( ‘post_type’ => ‘exhibitions’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘exhibition’, ‘field’ => ‘slug’ ), ) ); $query = new WP_Query($args); Assuming I’m on the right track, a verbal description of […]