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

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

Get single post from tags array

$args = array( ‘type’ => ‘post’, ‘orderby’ => ‘name’ ); $tags = get_tags($args); foreach($tags as $tag) { $the_query = new WP_Query( ‘tag=’.$tag->name ); if ( $the_query->have_posts() ) { $the_query->the_post(); $desired_posts[] = get_the_ID(); // all the post IDs stored here. } else { // no posts found } wp_reset_postdata(); } $args1 = array( ‘post_type’ => ‘post’, … Read more

Orderby my needs in foreach loop like by title or something?

Try below code to filter the data by title in Ascending Order: $meta = get_post_meta(get_the_ID(), ‘_custom-meta-box’, true ); $title_array = array(); foreach ($meta as $key11 => $value11) { if($meta[$key11] > 1) { $my_postid11 = $value11; $title = get_the_title($my_postid11); $id = $my_postid11; $title_array[$id] = $title; } } asort($title_array); foreach ($title_array as $key22 => $value22) { $my_postid22 … Read more

Styling text and images in the_content()

I think the problem is the way you use the foreach with HTML inside. I usually use this way, so try perhaps to modify your code like this : <?php if (have_posts()) { while (have_posts()) { the_post(); the_content(); // get_template_part( ‘template-parts/content’,’article’ ); $args = array( ‘post_type’ => ‘attachment’, ‘numberposts’ => -1, ‘post_status’ => null, ‘post_parent’ … Read more

Shortcode with a foreach and arguments

Here is your problem: foreach ($files[0] as $file) { There is no $files variable, so there is nothing to loop through. You can’t pull variables out of thin air and expect PHP to understand your intent. Computers are very literal, in the most extreme sense. They can’t intuit what you meant, or want. This code … Read more