Modifying the Search Results
add_filter( ‘pre_get_posts’, ‘__filter_pre_get_posts’ ); function __filter_pre_get_posts( $query ) { // this is to detect a public search query if ( ! is_admin() && $query->is_search ) { // DO your magic here… } }
add_filter( ‘pre_get_posts’, ‘__filter_pre_get_posts’ ); function __filter_pre_get_posts( $query ) { // this is to detect a public search query if ( ! is_admin() && $query->is_search ) { // DO your magic here… } }
Well, try the below code- $base_array = array( ‘posts_per_page’ => -1, ‘fields’ => ‘ids’, ‘post_type’ => ‘cpt’, ‘post_status’ => array(‘publish’), ‘date_query’ => array( ‘after’ => strtotime( ‘previous week Monday’ ), ‘before’ => strtotime( ‘previous week Friday’ ) ) ); $base = get_posts($base_array); I’ve not tested it. But I tested that below code returns the perfect … Read more
I think you need to use post__in . The code will be something like: $args = array( ‘post__in’ => array( 1, 2 ), ‘post_type’ => ‘attachment’, ‘post_mime_type’ => ‘image’, ‘no_found_rows’ => true, ‘posts_per_page’ => 2, ‘post_status’ => ‘any’ ); $query = new WP_Query($args);
You’ll need to use something other than a single WP_Query. You could use wp_list_pages() with a custom walker to get your desired structure. wp_list_pages in widget, sidebar, or wherever you want the list to appear: <ul class=”cpt-hierarchy”><!– or whatever class you like –> <?php wp_list_pages(array( ‘post_type’ => ‘cpt’, // replace with your cpt’s slug ‘title_li’ … Read more
In the last example (the one that’s not working for you), you’re instantiating an instance of the WP_Query class without passing in an array of query vars. That’s fine, but internally this means the query never actually takes place. You’re calling $q->set( … ), but that’s only setting a query variable, it doesn’t run the … Read more
You can check the post type in a conditional and echo a different ‘read more’ text based on this. Your $query is a WP_Query object and has a $post property. This is a WP_Post object of the current post and it has a $post_type property. You can access it directly with $query->post->post_type to check the … Read more
You’re missing the tax_query key, and it needs to be a nested array: $args = array( ‘post_type’ => ‘product’, ‘posts_per_page’ => -1, ‘tax_query’ => array( array( ‘taxonomy’ => ‘product_cat’, ‘terms’ => $cat_id, ‘field’ => ‘term_id’, ), ), ); Check the documentation
You can try the wpdb set_charset method (more info here). example use: $statyba_wpdb = new wpdb(STATYBA_USER, STATYBA_PASS, STATYBA_DB, STATYBA_HOST); $statyba_wpdb->set_charset($statyba_wpdb->dbh, ‘utf8’); Hope that helps.
Here’s one way translating it to minutes only: $args = [ ‘date_query’ => [ ‘after’ => ‘270 minutes ago’, // <– 4 hours and 30 minutes ago ‘inclusive’ => true ] ];
the_content filter takes only one parameter – $content, so you can’t check what post this $content comes from. So if the plugin Team performs incorrect checks (it can for example use is_singular( <POST_TYPE> )), then it will modify all contents printed on single team member page. You’ll have to check what functions are assigned to … Read more