How do you stop the rendering of the website to have something display on the front-end?

Assuming that you want the header and footer same for logged in and non-logged in users, you can add your IF condition in the file generating your front page (ex. front-page.php or index.php). This is completely dependent upon the theme you are using. For example in the WP’s default twentyseventeen theme, the front-page.php file calls … Read more

get custom post type value in header.php [closed]

I’m observing three problems here. 1- Your anchors do not have a href attribute. As you mentioned, the app_url field is a URL, and should be output in the href attribute of an anchor. So, this is how your anchor should look like: <a href=”https://wordpress.stackexchange.com/questions/293751/<?php echo esc_url( get_field(“app_url’ ) ); ?>”>My Link</a> Note that I’ve … Read more

Add more than one custom post type to wordpress home page post loop

Your second function overwrites the query of the first. It’s not necessary anyway as you can add as many post types to the $query->set line in the first function as you need, like this: $query->set( ‘post_type’, array( ‘post’, ‘first_function’, ‘my-second-post-type’,’another-post-type’ ) ); BTW, is your post type actually called ‘first_function’? Just asking as that’s the … Read more

WP_Query: Show 10 posts in date order, first three random

Try this: // All the rendered HTML $output=””; // The posts to exclude from the random query. $exclude = []; // The remaining non-random posts $remaining = new WP_Query([ ‘posts_per_page’ => 7, ]); // Run the remaining query first because we have to know what should be excluded in the random query. if {$remaining->have_posts()) { … Read more

Make a loop to return x number of posts, but only if they have content or excerpt

Below is an example — tested and worked. The SQL query is: AND ({$wpdb->posts}.post_content != ” OR {$wpdb->posts}.post_excerpt != ”) And the example: <?php // This would be in functions.php or somewhere else where appropriate. function posts_where_require_content_or_excerpt( $where, $wp_query ) { global $wpdb; $where .= ” AND (” . ” {$wpdb->posts}.post_content != ”” . ” … Read more

How to split a post and intercalate elements from a loop

You can buffer the template part to use it within post content: <?php add_filter( ‘the_content’, ‘add_related_each_nth_p’ ); function add_related_each_nth_p( $content ) { if ( ! is_single() ) { return $content; } // the interval between added content $paragraph_steps = 3; // declare empty output $output=””; // declare related posts offset $z = 0; // make … Read more

Get all posts with empty meta_value

If I understand your question correctly, you want to query for region field only if $region variable is not empty? If so, this should work and it will be much prettier code than the one you suggested: $meta_query = array( array( ‘key’ => ‘state’, ‘value’ => ‘Alabama’, ), ); if ( $region ) { $meta_query[] … Read more