Shortcode with ‘year’ parameter

With help from @bosco , I was able to figure it out. Below is the working code: //get archived posts per year add_shortcode( ‘archived-posts’, ‘archived_posts’ ); function archived_posts($atts) { $a = shortcode_atts( array( ‘year’ => date(‘Y’) ), $atts ); $q = new WP_Query(array( ‘post_type’ => ‘post’, ‘posts_per_page’ => -1 , ‘post_status’ => ‘archive’ , ‘year’ … Read more

Utilising an existing page while using the “s” query parameter

Custom Query Var Moving s to a custom query variable when a page is explicitly requested should be simple enough: function wpse390935_set_page_search_qv( $wp ) { $qvs = $wp->query_vars; if( empty( $qvs[‘s’] ) || ( empty( $qvs[‘pagename’] ) && empty( $qvs[‘page_id’] ) ) ) return; $wp->query_vars[‘page_search’] = $qvs[‘s’]; unset( $wp->query_vars[‘s’] ); } add_action( ‘parse_query’, ‘wpse390935_set_page_search_qv’ ); … Read more

WP Query causing timeout

I have figured out. I was missing $query1->the_post(); in the while loop and wp_reset_postdata(); after the loop ends. Final working code: <ul class=”pie-chart__legend” id=”donut1″> <?php $wcatTerms1 = get_terms(‘incident_type’, array(‘hide_empty’ => 0, ‘parent’ =>0)); foreach($wcatTerms1 as $wcatTerm1) { $args1 = array( ‘posts_per_page’ => -1, ‘post_type’ => ‘incident’, ‘post_author’ => $current_user->ID, ‘post_status’ => ‘publish’, ‘tax_query’ => array( … Read more

I need help using pre_get_comments to limit comments in the comments admin screen

Update In response to the new code in the updated question, you could actually use $wpdb->get_col() with a single SQL command via a JOIN clause, like so: $query = “SELECT c.comment_ID FROM $wpdb->comments c JOIN $wpdb->posts p ON p.ID = c.comment_post_ID WHERE c.user_id = $user_ID OR p.post_author = $user_ID”; $comment_ids = $wpdb->get_col( $query ); However, … Read more

Query all post and CPT from 2 specific taxonomies AND by ACF custom field

Finally I found a solution! Here is the query in case someone needs it : // first query $first_ids = get_posts(array( ‘fields’ => ‘ids’, ‘posts_per_page’ => ’10’, ‘post_status’ => ‘publish’, ‘post_type’ => array(‘post’), ‘orderby’ => ‘date’, ‘order’ => ‘DESC’, )); // second query $second_ids = get_posts(array( ‘fields’ => ‘ids’, ‘posts_per_page’ => ’10’, ‘post_status’ => ‘publish’, … Read more

Should $query-> be used with conditional tags?

As background, there are functions in WordPress that tell you certain things about the main query. For example, is_search(), is_archive() etc. will tell you whether the main query is a search query, or an archive query respectively. These typically, but not necessarily, line up with where certain templates will be used. You use these functions … Read more

Having Issue on Ordering CPT by Custom Field In Custom WP Query

Your query args are not quite correct. When you want to order by a custom field, you need to specify a meta_key argument, and set your orderby to the kind of ordering you need. For example: $args = array( ‘tax_query’ => array( array( ‘taxonomy’ => ‘topic’, ‘field’ => ‘slug’, ‘terms’ => ‘movie’, ), ), ‘post_type’ … Read more