Custom Post type category pages template and loop

You may alter the main query before the loop, but it’s crucial to reset the main query afterwards. Otherwise you’ll probably run into problems elsewhere. Disclaimer: Doing this is officially discouraged by WordPress here. However, in my experience it works perfectly to achieve the behaviour you want. Just don’t forget to add wp_reset_query(); after closing … Read more

Exclude current post from loop

Try this: For your single-accessory.php template: <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <?php // excludes this post from ‘Related posts’ in the sidebar $GLOBALS[‘current_id’] = $post->ID; ?> For your sidebar or where you want to show related posts: <?php if (is_singular(‘accessory’) ) : global $post; $categories = get_the_category(); $exclude = $GLOBALS[‘current_id’]; $args … Read more

Split wordpress loop to multiple layouts

Just create 2 queries using the “offset” parameter and separate them by: <?php wp_reset_query(); ?> Display posts from the 4th one (offset is starting from 0): <?php $query = new WP_Query( ‘offset=3′ ) ); ?> EDIT: Here’s some sample code: <?php query_posts(‘offset=0&showposts=2&order=ASC’); ?> <?php if(have_posts()) : while(have_posts()) : the_post(); ?> <p><a href=”https://wordpress.stackexchange.com/questions/61605/<?php the_permalink(); ?>”><?php the_title(); … Read more

Only display post if published in last 24 hours?

As birgire said date query is an array of arrays May be this solves your problemo. $args = array( ‘post_type’ => ‘surf_reports’, ‘posts_per_page’ => ‘1’, ‘category_name’ => $cat (this is pulled dynamically in my template), ‘date_query’ => array( array( ‘after’ => ’24 hours ago’ ) ) );

ACF custom field in [closed]

In the header.php template, you cannot access the $post variable. So you will have to map it using $wp_query, as mentioned on ACF forum here. Try this: <?php global $wp_query; $post = $wp_query->post; $background = get_field(‘background’, $post->ID); ?> <style> .site-header { background: url(<?php echo $background; ?>) no-repeat center; background-size: cover; } </style>