Can not switch the queried post in pre_get_posts hook

Huh. I double-checked. On my local server, this bit of code successfully changes the post: function test_redirect() { global $wp_query; $wp_query->set(‘page_id’, 5); } add_action(‘pre_get_posts’, ‘test_redirect’); You’re going to have to do a bit of debugging. On a dev server, var_dump the $wp_query variable a few key places to check that it has what you expect … Read more

Filtering custom post type query

Yes, you can do that. Just remove the first foreach and give the General category ID and change the code like below- // Initiating shortcode. Place this code to any of your page to get your desired output. add_shortcode( ‘faq_page_content’, ‘the_dramatist_faq_page_content’); /** * Rendering function */ function the_dramatist_faq_page_content() { echo ‘<ul>’; $posts = get_posts( array( … Read more

get_posts() seemingly ignoring post_type

I built a workaround for now, but would really love to know what is causing this. The workaround was obtained by removing changing “suppress_filters” to true and then adding a function that adds to the where clause of the SQL… But I would rather know how to fix this at the root rather than a … Read more

get excerpt without images

Use the_excerpt(); wordpress function to show only text. That function will filter out some html tags such as <img> , <a>. A useful alternative to show only plain text. Note – The the_excerpt() function internally uses get_the_excerpt() to get excerpt and return a new string by filtering tags such as <img>, <a> tags. It also … Read more

use get_posts to get custom field data, but in one array

You can alter your foreach loop as following to get concert date and city pair in single multidimentional array as following. $concert_query = array(); $i = 0; foreach($c_query as $post) : setup_postdata($post); $concert_query[$i][‘concert_date’] = get_post_meta(get_the_ID(), ‘concert_date’, true); $concert_query[$i][‘concert_city’] = get_post_meta(get_the_ID(), ‘concert_city’, true); $i ++; endforeach; print_r($concert_query);

Get all posts without tags

A WP_Query where ‘tax_query’ has all tag terms and operator ‘NOT IN’: $tags = get_terms(‘post_tag’, array(‘fields’=>’ids’) ); $args = array( ‘post_type’ => ‘post’, ‘posts_per_page’ => -1, ‘tax_query’ => array( array( ‘taxonomy’ => ‘post_tag’, ‘field’ => ‘id’, ‘terms’ => $tags, ‘operator’ => ‘NOT IN’ ) ) ); $untagged = new WP_Query( $args );

get_posts cannot grab from specific category

Edit In response to OP’s answer: So you use post_type and add cat at the end. Like [tribe_events][_cat]=[value] This is absolutely incorrect. WordPress does not automatically create custom taxonomies in this manner. From the OP’s comment: I’m using tribe Events calendar. Check it there. Here is the relevant PHP file from the The Events Calendar … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)