The Loop in Static Page

This quite a broad question to answer. I’m not going to go into detail here and into core code, you’ll need to go and read the links I’m going to provide. I’m going to try to keep my answer sweet and short and useful 🙂 Take the bundled theme twentyfourteen for example, when you open … Read more

Modify main loop in taxonomy archive page

You could hijack the $query just before fetching the posts. function wpdev_156674_pre_get_posts( $query ) { if ( $query->is_main_query() && $query->is_tax( ‘region’ ) ) { // Manipulate $query here, for instance like so $query->set( ‘orderby’, ‘meta_value_num’ ); $query->set( ‘meta_key’, ‘event_date’ ); $query->set( ‘order’, ‘DESC’ ); } } add_action( ‘pre_get_posts’, ‘wpdev_156674_pre_get_posts’ ); References: pre_get_posts action hook WP_Query … Read more

Displaying Only Certain Tags in Loop

Create a must-use plugin. Put it in <docroot>/wp-content/mu-plugins/selective-posts.php Following should be the code in selective-posts.php to filter specific posts. function golfclubs_tag( $query ) { if ( $_SERVER[‘HTTP_HOST’] === ‘www.golfclubreviewdomain.com’ ) { $query->set( ‘tag’, ‘golfclubs’ ); } } add_action( ‘pre_get_posts’, ‘golfclubs_tag’ ); This way it would filter all the queries across the site for specific domain … Read more

Automatically insert php function into post $the_content

I’m sure you want to use the_content filter instead of the default_content filter (already mentioned by @jgraup) because what happens if the generated HTML changes? Then you’re stuck with it in your content. It’s better to add it dynamically. Here’s one suggestion: add_filter( ‘the_content’, function( $content) { if( ! in_the_loop() ) return $content; if( ‘property’ … Read more