Get posts from category with custom query

It looks like this is the new part of this query causing the problem, is that right? (SELECT term_taxonomy_id FROM wp_BOMEGAterm_relationships WHERE object_id = p.ID) AS categories If so the error message is clear: a sub-select in this query should only return one row. If it returns more than one row it doesn’t know how … Read more

$post->ID not working in combination with a custom query

That $query->have_posts() modifies the global $post variable which is also used on the admin side, and on the front-end/public side of the site, you would simply call wp_reset_postdata() to restore the global $post back to the post before you call the $query->have_posts(). But on the admin side, you need to manually restore the variable like … Read more

Delete post revisions only for a single post

If you need an SQL query, then this option should be suitable function src_flush_revisions () { global $wpdb; $post_id = 5//exp post id if ( isset( $timeLimit ) ) { $revision_ids = $wpdb->get_col( $wpdb->prepare( “SELECT `ID` FROM $wpdb->posts WHERE `post_type` = ‘revision’ AND `post_parent` = %d”, $post_id ) ); foreach ( $revision_ids as $revision_id ) … Read more

Can I make get_users() query global?

You can use the WordPress functions apply_filters and add_filters to store and retrieve data, like so: // The filter callback function. function so_wp_380975_get_user_args( $array ) { // (maybe) modify $array. // for now, we just return the array return [ ‘meta_key’ => ‘mycred_default’, ‘orderby’ => [ ‘meta_value_num’ => ‘DESC’ ], ‘order’ => ‘desc’, ‘number’ => … Read more

Very complex post query

I got inspired in solving my problem by this thread! The idea is to create individual queries (unordered to save time, as sorting is not needed at this stage) to get the post IDs that meet your criteria; then take those IDs and run a final query with the IDs as the criteria to get … Read more

WordPress query undefined offset in loop

There might be other causes to the issue in question, but one issue I noticed in your code is that because you are looping through a custom WP_Query instance, i.e. $loop, then you need to use $loop->the_post() instead of just the_post(): while ( $loop->have_posts() ) { $loop->the_post(); the_title(); } And you could see that I … Read more