Fix incorrect related posts code snippet

Your first problem: Try to write down what you want to do: You do not want to print posts that are already printed. So you have to remember what posts are already printed. In PHP normally an array is a good solution to remember things that are already done. Let’s add an array: $printed_posts = … Read more

List posts related to category on a div [closed]

Here is a start. Create a template called content-related.php Inside that paste the following code <?php /** * The default template for displaying realted posts * * @package WordPress * @subpackage Pieter Goosen * @since pietergoosen 1.0 */ wp_reset_postdata(); global $post; // Define shared post arguments $categories = get_the_category($post->ID); if ($categories) : $category_ids = array(); … Read more

Query for page content, and query for posts on the same page?

Use query link this. You are checking posts in $the_query. but you have used $query. <?php $custom_query = new WP_Query( ‘posts_per_page=4’ ); if ( $custom_query->have_posts() ) : while ( $custom_query->have_posts() ) : $custom_query->the_post(); ?> <h2><?php the_title(); ?></h2> <?php endwhile; else : get_template_part( ‘content’, ‘none’ ); endif; wp_reset_postdata(); ?>

display custom post type from register taxonomy

First off, I’d like to note a few things wrong with your Post Type and Taxonomy set up. There’s a few settings in your $labels that don’t make sense: $labels = array( … ‘post_type’ => ‘attachment’, ‘post_parent’ => $post->ID, ‘post_status’ => ‘inherit’, ‘post_mime_type’ => ‘image’, ); These last 4 options don’t make much sense ( … Read more

Add banner after the third post [closed]

It’s not related to WordPress at all, it’s a generic PHP question, hence off-topic here. It’s easy, follow the inline comments, and you can have it. 🙂 <?php //declare a counter $counter = 1; // Start the Loop. while ( have_posts() ) : the_post(); /* * Include the post format-specific template for the content. If … Read more

How to create a loop inside WP_Query?

Just construct what you need outside of the main query. // terms to search $meta_query_keys = array(‘Panera Group 2 Encino’, ‘West Hollywood’); // start the meta query off $meta_query = array(‘relation’ => ‘OR’); // add terms to query foreach($meta_query_keys as $key) { $meta_query[] = array( ‘key’ => ‘user_group_name’, ‘value’ => $key, ‘compare’ => ‘LIKE’, ); … Read more