Querying another post category to match current post and display in loop

if you are adding the custom query into the single template, try working with get_the_category() to get the cat_id for your query; also, get_posts() does not work with if( have_posts() ) etc. example code, using a custom query: <?php $cat = get_the_category(); $cat_id = $cat[0]->term_ID; $cpt_match_query = new WP_Query( array( ‘posts_per_page’ => 2, ‘post_type’ => … Read more

Get post format

If you’re outside the loop, pass a post ID. $format = get_post_format( $post_id ); To guard against missing formats, add a default to your template: $format = get_post_format() ? : ‘standard’; Then you can use your same IF statement: if ( $format == ‘link’ ) :

Random posts that always include a particular post?

Try this code:: post__in (array) – use post ids. Specify posts to retrieve. ATTENTION If you use sticky posts, they will be included (prepended!) in the posts you retrieve whether you want it or not. <?php $parent = $post->ID; $paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1; $query_args = array( ‘post_type’ => ‘page’, ‘post_in’ => array(‘post_id_to_include’), … Read more

How can I get “Previous” and “Next” to show in the navigation besides the links?

You may like to use the_posts_pagination() instead of the_posts_navigation() or get_next/previous_posts_link(). The posts pagination function outputs a set of page numbers with links to the previous and next pages of posts. Example format would be like this below: <div class=”pagination_style”> <?php the_posts_pagination(array ( ‘prev_text’ => __( ‘PREV’ ), ‘next_text’ => __( ‘NEXT’ ), ‘screen_reader_text’ => … Read more

Display selected categories onto post page

If what I understand from your question is correct. You have a post that categorized in multiple categories and subcategories. I have already made the same in a website. use these following code bellow so a sub categories will displayed after the parent category. //first part $allcats = get_the_category(); $parent_id = $all_ids = array(); foreach … Read more

WordPress post next/prev not working

I made some updates in your code. Please, try this updated version. <div id=”demo”> <?php $wp_query = new WP_Query( array( ‘category_name’ => ‘Case Study’, ‘posts_per_page’ => 1, )); ?> <?php if ( $wp_query->have_posts() ) : ?> <?php while ( $wp_query->have_posts() ) : the_post(); ?> <?php the_title(); ?> <?php the_content(); ?> <?php endwhile; ?> <div class=”nav-previous … Read more