Custom post type appearing within the previous one on archive.php

Your closing tags for the card and card body divs are outside of the loop. try this: <?php get_header(); if (have_posts()) : while (have_posts()) : ?> <div class=”card container”> <a href=”https://wordpress.stackexchange.com/questions/333813/<?php // this conditional outputs a different link url for CPT”resources’ if (is_post_type_archive( $resources )) { echo ‘https://’ . get_field(‘website’); } else { echo get_the_permalink(); … Read more

get author_name from queried post

The problem with your code lies in these three lines: $queried_post = get_post($post_id); $author_id = $queried_post->post_author; $first = $user_info->user_nicename; You correctly get authors ID, but then you try to get some field of user_info variable, which is not defined anywhere in your code. One way to fix it is to get user info (using get_userdata) … Read more

Including post thumbnail url in loop’s post object to reduce number of queries

I believe you can fetch that data using setup_postdata() which lets you access all the data relating to a post and use it with standard template tags (in your case, the_post_thumbnail). There is a great tutorial here: https://wpshout.com/setup_postdata-template-tags-need-custom-wp_post-arrays-crave/ Important to note that you first have to setup the global $post and you have to be … Read more

Loop in Related Posts WordPress

Rewrite your code like this condition. This will display the code as you expected. <!– Related Posts START–> <?php $query = get_max_related_posts(); if ( $query ) { $i=1; ?> <div class=”td_block_wrap td_block_7 td_block_widget td_uid_3_5de39f94df644_rand td-pb-border-top td_block_template_1″> <h4 class=”block-title”> <span class=”td-pulldown-size”>Berita Terkait</span> </h4> <div class=”td_block_inner”> <?php while ( $query->have_posts() ) { $query->the_post(); if($i%2!=0){?> <div class=”td-block-row”><?php }?> … Read more