How to find a post id using the post_excerpt?

You can get the post ID from the excerpt, but as far as I can tell, WP_Query doesn’t support this (very well), so you need to write a custom WPDB query. function get_post_id_by_excerpt($excerpt) { global $wpdb; $result = $wpdb->get_row( $wpdb->prepare(“SELECT ID FROM {$wpdb->prefix}posts WHERE post_excerpt LIKE %s”, $excerpt) ); return $result; } For this to … Read more

pre_get_posts Remove tax_query Completely

This fixed it! 🙂 Hat-tip gmazzap for the useful info: Obliterate the main query and replace it function wpse_286813_omit_all( $query_vars ){ // triggered also in admin pages if ( is_admin() ) return $query_vars; if( !empty($query_vars[‘taxo’]) && $query_vars[‘taxo’] === ‘all’ ){ $query_vars[‘taxo’]=”; } return $query_vars; } add_filter( ‘request’, ‘wpse_286813_omit_all’ );

how to link to detail page(single.php?) in a wp_loop

Replace with below code : <?php $args = …..; $query = new WP_Query($args); while($query->have_posts() ) : $query->the_post(); ?> <div class=”each”> <h4><a href=”https://wordpress.stackexchange.com/questions/289892/<?php the_permalink();?>” title=”<?php the_title_attribute();?>”><?php the_title();?></a></h4> </div> <?php endwhile; wp_reset_query(); ?>

Automatic value for custom fields for posts

Try meta_query to get posts having theme_settings_post_show == true (for new posts) and theme_settings_post_show not set at all (for old posts): <?php $queryArguments = array( ‘posts_per_page’ => -1, ‘post_type’ => ‘post’, ‘meta_query’ => array( ‘relation’ => ‘OR’, // value is not set or true array( ‘key’ => ‘theme_settings_post_show’, ‘value’ => ”, // can be any … Read more

wp_query not searching with apostrophe

Try using sanitize_text_field instead of esc_html wp> $search_query = “Dalton’s Law <br/>”; string(18) “Dalton’s Law <br/>” wp> $query = apply_filters( ‘get_search_query’, $search_query ); string(18) “Dalton’s Law <br/>” wp> $esc_html = esc_html( $query ); string(29) “Dalton&#039;s Law &lt;br/&gt;” wp> $sanitized = sanitize_text_field( $query ); string(12) “Dalton’s Law” esc_html should be used to escape output before it … Read more

Offset Page Loops and Pagination

I messed around with the code some more, and my particular issue actually ended up relating to the original if statement parameters. Changing the condition to check the home page for queries to if ( $query->is_home() && ! $query->is_main_query() ) { return; } and else { //This is the first page. Just use the offset… … Read more