Advanced custom fields repeater with post object not repeating content - wordpress

I am attempting to use a repeater with a post object inside as seen here:
Picture of ACF repeater with post object
It is only showing one out of two Reps:
Rep map
Here is the code I am using to attempt to accomplish this:
<?php
$args = array(
'post_type' => 'find-your-rep',
'post_status' => 'publish',
'posts_per_page' => -1,
);
$loop = new WP_Query( $args );
$i = 0;
?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); $i++ ?>
<span id="div<?php echo $i ?>" class="targetDiv">
<div class="repCard">
<?php if ( have_rows( 'reps' ) ) : ?>
<?php while ( have_rows( 'reps' ) ) : the_row(); ?>
<h3><?php the_sub_field( 'location' ); ?></h3>
<?php $rep = get_sub_field( 'rep' ); ?>
<?php if ( $rep ) : ?>
<?php $post = $rep; ?>
<?php setup_postdata( $post ); ?>
<div class="fullname"><?php the_title() ?></div>
<?php if ( get_field( 'company' ) ) : ?><div class="company">
<?php the_field( 'company' ); ?></div>
<?php endif; ?>
<?php if ( get_field( 'phone' ) ) : ?>
<div class="phone"><i class="phone icon"></i>
<a href="tel:<?php the_field( 'phone' ); ?>">
<?php the_field( 'phone' ); ?></a>.
</div>.
<?php endif; ?>
<?php if ( get_field( 'email' ) ) : ?>
<div class="email">
<i class="envelope icon"></i> <a href="mailto:<?php the_field( 'email' ); ?>">
<?php the_field( 'email' ); ?></a></div>
<?php endif; ?>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
<?php endwhile; ?>
<?php else : ?>
Sorry, there's no rep assigned to this location.
<?php endif; ?>
</div>
</span>
<?php endwhile; wp_reset_postdata(); ?>
I'd appreciate any help/direction to resolve this.

Related

Pagination not working on the Category Template

I m trying to add the pagination for the category template in my application but when i click on the next option it redirect's me to the page and say no page found. The Same Code i Have written for the blog page too it is working but only in case of categories page it is not working. Can anyone please help me for this
<?php
/**
* A Simple Category Template
*/
get_header();
$current_page = get_queried_object();
$category = $current_page->name;
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$query = new WP_Query(
array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page'=> 1,
'category_name' => $category,
'paged' => $paged
)
);
?>
<div id="content" role="main">
<?php
// Check if there are any posts to display
if ( $query->have_posts() ) :
// The Loop
while ( $query->have_posts() ) : $query->the_post();
$image_id = get_post_thumbnail_id();
$image_src = wp_get_attachment_image_src($image_id, $size)[0];
?>
<br>
<section>
<article>
<img width="270" height="178" src="<?php echo $image_src; ?>">
</article>
<nav>
<ul>
<?php
foreach((get_the_category()) as $category) ?>
<li> | <?php echo get_the_date(); ?></li>
<li><a href="<?php the_permalink(); ?>/">
<?php the_title(); ?></a></li>
<li>
<img width="40" height="40" src="<?php echo $image_src ?>">
</li>
<li><?php echo get_the_author(); ?></li>
</ul>
</nav>
</section>
<?php endwhile; ?>
<?php //echo "<pre>"; ?>
<?php //var_dump($query); ?>
<?php //echo "</pre>"; ?>
<p><?php next_posts_link('Next',$query->max_num_pages); ?></p>
<p><?php previous_posts_link('Previous'); ?></p>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
</div>
<?php
get_footer();
?>

Displaying short product description of woocommerce product via ACF Repeater field

My code is below
It’s essentially bringing out a woocommerce product as a post object inside a repeater field.
It’s pretty much working fine with two exceptions.
It’s giving an error for using get_attribute for the $scent variable
The $description variable should pull the Product Short Description, but its not bringing anything back.
Any help would be very much appreciated!
<?php if ( have_rows( 'products' ) ) : ?>
<?php while ( have_rows( 'products' ) ) : the_row(); ?>
<?php $post_object = get_sub_field( 'product' ); ?>
<?php if ( $post_object ): ?>
<?php $post = $post_object; ?>
<?php setup_postdata( $post );
global $post;
$logoImageHtml = '';
$subCollectionHtml = '';
$imageAlt = '';
$hoverImage = '';
$args = array(
'taxonomy' => 'product_cat',
'orderby' => 'parent',
'order' => 'ASC',
'menu_order' => 'ASC',
'pad_counts' => 0,
'hierarchical' => 1,
'hide_empty' => 1
);
$terms = wc_get_product_terms(get_the_ID(), 'product_cat', $args);
if (!empty($terms) && is_array($terms)) {
$terms = array_reverse($terms);
$term = (!empty($terms[1]) ? $terms[1] : null);
if (!empty($term->name)) {
$imageAlt = $term->name;
}
$term = (!empty($terms[2]) ? $terms[2] : null);
if (!empty($term->name)) {
$subCollectionHtml = "{$term->name}
";
}
}
$scent = $post->get_attribute('scent');
$scent = (!empty($scent) ? explode(', ', $scent) : null);
$description = get_short_description ( $post->post->ID );
// $description = $post->post->post_excerpt;
$thumbImage = wp_get_attachment_image_src( get_post_thumbnail_id( $post->post->ID ), 'shop_catalog' );
if (get_field('product_logo_image')) {
$logoImage = get_field('product_logo_image');
if (!empty($logoImage)) {
$logoImageHtml = "<h3><img class='product-logo' src='$logoImage' alt='$imageAlt'/></h3>";
}
}
if (get_field('product_grid_scent_image')) {
$hoverImage = get_field('product_grid_scent_image');
}
?>
<li class="product">
<div class="front">
<div class="image">
<?php if (!empty($thumbImage)): ?>
<img src="<?php echo $thumbImage[0]; ?>" data-id="<?php echo $post->post->ID; ?>">
<?php endif; ?>
</div>
<?php if ($logoImageHtml || $subCollectionHtml || $scent): ?>
<div class="text">
<?php echo $logoImageHtml; ?>
<?php echo $subCollectionHtml; ?>
<?php
if (!empty($scent) && is_array($scent)): ?>
<div class="scent">
<ul>
<?php foreach ($scent as $key => $value): ?>
<li><?php echo $value; ?></li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
</div>
<?php endif; ?>
</div>
<div class="back">
<div class="frame">
<div class="content">
<?php if (!empty($hoverImage)): ?>
<div class="image">
<img src="<?php echo $hoverImage; ?>" alt="Scent"/>
</div>
<?php endif; ?>
<div class="text">
<?php
if (!empty($description)): ?>
<?php echo $description; ?>ssss
<?php endif; ?>
View details
</div>
</div>
</div>
</div>
</li>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
<?php endwhile; ?>
<?php else : ?>
<?php // no rows found ?>
<?php endif; ?>

Two custom loops on same page in wordpress?

I wasn't able to find anything on here, so I am bringing this question to you. The following code does mainly what I want, only the page-cycle doesn't work: When I want to navigate to older posts, the page that is seen displays the same new posts again. How do I do this properly?
So index.php has two loops:
<?php
$args = array( 'numberposts' => 1,
'post_status'=>"publish",
'post_type'=>"post",
'orderby'=>"post_date");
$postslist = get_posts( $args );
foreach ($postslist as $post) : setup_postdata($post);
?>
// regular post html with wp tags
<?php endforeach; ?>
<?php
query_posts('posts_per_page=12&offset=1');
if (have_posts()) : ?>
<h3>Headline</h3>
<?php while (have_posts()) : the_post(); ?>
// regular html with wp tags for these posts (teasers, with the_excerpt)
<?php endwhile; ?>
<div class="navigation">
<span class="nextlink"><?php next_posts_link( 'Older', 0 ); ?></span>
<span class="previouslink"><?php previous_posts_link( 'Newer' ); ?></span>
</div>
<?php else : ?>
<h3><?php _e('Nothing found'); ?></h3>
<?php endif; ?>
Here is the explanation: One visits the blog: The most recent blog post is displayed in full length in one block, the 12 older posts (excluding the first one with offset, so 2–13) are displayed in another block with content teasers and a next-previous-navigation at the bottom to display post teasers 14–25 and so on. (The problem: it's always 2–13)
// Edit: Code in response to the top answer, now the full code of the index.php. Notice, that the HTML has changed, since I have used normalized HTML, since it should usually not matter. This times it's the actual code.
<?php get_header(); ?>
<div class="box blog-block">
<?php
$args = array( 'numberposts' => 1, 'post_status'=>"publish",'post_type'=>"post",'orderby'=>"post_date");
$postslist = get_posts( $args );
foreach ($postslist as $post) : setup_postdata($post); ?>
<span class="head"><?php the_time('j. F Y') ?></span>
<h3><?php the_title(); ?></h3>
<div class="entry">
<?php global $more;
$more = 1;
the_content();
?>
<p class="author"><?php the_author(); ?></p>
<p><a class="more-link" href="<?php the_permalink(); ?>#respond" title="<?php the_title();?>">Kommentieren</a>
</div>
<?php endforeach;
wp_reset_postdata(); /* 1. reset post data */
?>
</div>
<div class="box" id="recentposts">
<?php
$paged = ( get_query_var('page') ) ? get_query_var('page') : 1;
$display_count = 12;
$excluded_count = 1;
$offset = ( ($paged-1) * $display_count ) + $excluded_count;
$args = array(
'post_status'=>"publish",
'post_type'=>"post",
'orderby'=>"post_date",
'posts_per_page' => $display_count,
'offset' => $offset,
'paged' => $paged
);
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) : ?>
<h3>Bisherige Artikel</h3>
<div class="recentpostsmasonry">
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<div <?php post_class('halb'); ?> id="post-<?php the_ID(); ?>">
<span class="head"><?php the_time('j. F Y') ?></span>
<h3><?php the_title(); ?></h3>
<div class="entry">
<?php the_excerpt(); ?>
<p class="more-link">Weiterlesen ...</p>
<p class="comments"><?php edit_post_link(__('Bearbeiten'), '', ' | '); ?> <?php comments_popup_link(__('Schreib den ersten Kommentar'), __('Ein Kommentar'), __('% Kommentare'), '', __('') ); ?></p>
</div>
</div>
<?php endwhile; ?>
</div>
<div class="navigation">
<span class="nextlink" title="Ältere Einträge"><?php next_posts_link( '«', 0 ); ?></span>
<span class="previouslink" title="Jüngere Einträge"><?php previous_posts_link( '»' ); ?></span>
</div>
<?php else : ?>
<h3><?php _e('Nichts gefunden :('); ?></h3>
<?php endif; ?>
</div>
I am trying out this code now (14.10.17), but it doesn't add functioning page navigation...:
<?php get_header(); ?>
<div class="box blog-block">
<?php
$args = array( 'numberposts' => 1, 'post_status'=>"publish",'post_type'=>"post",'orderby'=>"post_date");
$postslist = get_posts( $args );
foreach ($postslist as $post) : setup_postdata($post); ?>
<span class="head"><?php the_time('j. F Y') ?></span>
<h3><?php the_title(); ?></h3>
<div class="entry">
<?php global $more;
$more = 1;
the_content();
?>
<p class="author"><?php the_author(); ?></p>
<p><a class="more-link" href="<?php the_permalink(); ?>#respond" title="<?php the_title();?>">Kommentieren</a>
</div>
<?php endforeach;
wp_reset_postdata(); /* 1. reset post data */
?>
</div>
<div class="box" id="recentposts">
<?php
$paged = ( get_query_var('page') ) ? get_query_var('page') : 1;
$display_count = 12;
$excluded_count = 1;
$offset = ( ($paged-1) * $display_count ) + $excluded_count;
$args = array(
'post_status'=>"publish",
'post_type'=>"post",
'orderby'=>"post_date",
'posts_per_page' => $display_count,
'offset' => $offset,
'paged' => $paged
);
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) : ?>
<h3>Bisherige Artikel</h3>
<div class="recentpostsmasonry">
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<div <?php post_class('halb'); ?> id="post-<?php the_ID(); ?>">
<span class="head"><?php the_time('j. F Y') ?></span>
<h3><?php the_title(); ?></h3>
<div class="entry">
<?php the_excerpt(); ?>
<p class="more-link">Weiterlesen ...</p>
<p class="comments"><?php edit_post_link(__('Bearbeiten'), '', ' | '); ?> <?php comments_popup_link(__('Schreib den ersten Kommentar'), __('Ein Kommentar'), __('% Kommentare'), '', __('') ); ?></p>
</div>
</div>
<?php endwhile; ?>
</div>
<div class="navigation">
<span class="nextlink" title="Ältere Einträge"><?php next_posts_link( '«', 0 ); ?></span>
<span class="previouslink" title="Jüngere Einträge"><?php previous_posts_link( '»' ); ?></span>
</div>
<?php else : ?>
<h3><?php _e('Nichts gefunden :('); ?></h3>
<?php endif; ?>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
New:
<?php get_header(); ?>
<div class="box blog-block">
<?php
$args = array( 'numberposts' => 1, 'post_status'=>"publish",'post_type'=>"post",'orderby'=>"post_date");
$postslist = get_posts( $args );
foreach ($postslist as $post) : setup_postdata($post); ?>
<span class="head"><?php the_time('j. F Y') ?></span>
<h3><?php the_title(); ?></h3>
<div class="entry">
<?php global $more;
$more = 1;
the_content();
?>
<p class="author"><?php the_author(); ?></p>
<p><a class="more-link" href="<?php the_permalink(); ?>#respond" title="<?php the_title();?>">Kommentieren</a>
</div>
<?php endforeach;
wp_reset_postdata(); /* 1. reset post data */
?>
</div>
<div class="box" id="recentposts">
<?php
$paged = ( get_query_var('page') ) ? get_query_var('page') : 1;
$display_count = 12;
$excluded_count = 1;
$offset = ( ($paged-1) * $display_count ) + $excluded_count;
$args = array(
'post_status'=>"publish",
'post_type'=>"post",
'orderby'=>"post_date",
'posts_per_page' => $display_count,
'offset' => $offset,
'paged' => $paged
);
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) : ?>
<h3>Bisherige Artikel</h3>
<div class="recentpostsmasonry">
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<div <?php post_class('halb'); ?> id="post-<?php the_ID(); ?>">
<span class="head"><?php the_time('j. F Y') ?></span>
<h3><?php the_title(); ?></h3>
<div class="entry">
<?php the_excerpt(); ?>
<p class="more-link">Weiterlesen ...</p>
<p class="comments"><?php edit_post_link(__('Bearbeiten'), '', ' | '); ?> <?php comments_popup_link(__('Schreib den ersten Kommentar'), __('Ein Kommentar'), __('% Kommentare'), '', __('') ); ?></p>
</div>
</div>
<?php endwhile; ?>
</div>
<div class="navigation">
<span class="nextlink" title="Ältere Einträge"><?php next_posts_link( '«', $the_query->max_num_pages ); ?></span>
<span class="previouslink" title="Jüngere Einträge"><?php previous_posts_link( '»' ); ?></span>
</div>
<?php else : ?>
<h3><?php _e('Nichts gefunden :('); ?></h3>
<?php endif; ?>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
You haven't set up paging, so your query always thinks its on page 1.
Also according to the WP Developer Resources , you shouldn't use query_posts- use WP_Query or pre_get_posts instead, so I'm using WP_Query below to do your 2nd query.
Note that I've assumed you are using this on a static homepage, but I've added the change required for a custom page in comments.
<?php
$args = array( 'numberposts' => 1,
'post_status'=>"publish",
'post_type'=>"post",
'orderby'=>"post_date");
$postslist = get_posts( $args );
foreach ($postslist as $post) : setup_postdata($post);
?>
// regular post html with wp tags
<?php endforeach;
wp_reset_postdata(); /* 1. reset post data */
?>
<?php
/* Set up your pagination - $paged will contain the current page, telling WP_Query which post to start with (e.g. #13 on page 2) */
$paged = ( get_query_var('page') ) ? get_query_var('page') : 1;
/* NOTE: if this is NOT on a static page
get the 'paged' query var instead of 'page', i.e.:
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
*/
$display_count = 12; /* variable for the number of posts per page */
$excluded_count = 1; /* the number of posts excluded from the start position */
/* Calculate the offset, i.e. the post number to start the page with
Normally this is calculated by: ($paged-1) * $display_count
so we just need to add 1 for the one we excluded */
$offset = ( ($paged-1) * $display_count ) + $excluded_count;
/* set up your new query passing in the page so WP_Query knows what to return */
$args = array(
'post_status'=>"publish",
'post_type'=>"post",
'orderby'=>"post_date",
'posts_per_page' => $display_count,
'offset' => $offset,
'paged' => $paged
);
/* set up your new query */
$the_query = new WP_Query( $args );
<?php if ( $the_query->have_posts() ) : ?>
<h3>Headline</h3>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
// regular html with wp tags for these posts (teasers, with the_excerpt)
<?php endwhile; ?>
<div class="navigation">
<span class="nextlink"><?php next_posts_link( 'Older', $the_query->max_num_pages ); ?></span>
<span class="previouslink"><?php previous_posts_link( 'Newer' ); ?></span>
</div>
<?php else : ?>
<h3><?php _e('Nothing found'); ?></h3>
<?php endif; ?>
The above code is untested, but the basic logic should be right.
UPDATE:
next_posts_link and
previous_posts_link use the global variable $wp_query by default, so to make is use your custom query, pass $custom_query->max_num_pages into next_posts_link, e.g.:
<span class="nextlink"><?php next_posts_link( 'Older', $the_query->max_num_pages ); ?></span>
<span class="previouslink"><?php previous_posts_link( 'Newer' ); ?></span>

Wordpress pagination not working with wp_pagenavi

i am showing posts using shortcode, and it is showing only 5-posts, i am using wp_pagenavi plugin for pagination, but pagination not showing. Following is my code, please help.
global $post;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array( 'post_type' => 'post', 'cat' => '2', 'paged' => $paged );
$loop = new WP_Query( $args );
if ( $loop->have_posts() ) {
ob_start();
?>
<div class="clearfix"></div>
<div class="issue-articles-wrap all-articles-wrap">
<?php
while ( $loop->have_posts() ) : $loop->the_post();
$loop->the_post();
$thumb_url = '';
$full_width = 'full-width-article';
if( has_post_thumbnail() ){
$thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'thumbnail' );
$thumb_url = $thumb['0'];
$full_width = '';
}
if( $post->ID > 0 ){
?>
<div class="issue-item issue-item-<?php echo $post->ID; ?>">
<?php if( $thumb_url != '' ){ ?>
<div class="thumb-article">
<img src="<?php echo $thumb_url; ?>" alt="<?php the_title(); ?>">
</div><!--thumb-article-->
<?php } ?>
<div class="summary-article <?php echo $full_width; ?>">
<h3><?php the_title(); ?></h3>
<?php the_excerpt(); ?>
</div><!--summary-article-->
<div class="clearfix"></div>
</div><!--issue-item-->
<?php
} // end of if( $post->ID > 0 )
endwhile;
wp_pagenavi();
wp_reset_query();
?>
</div><!--issue-articles-wrap all-articles-wrap-->
<?php
$rep = ob_get_contents();
ob_end_clean();
} // end of if ( $loop->have_posts() )
return $rep;
I also tried custom pagination, but it fails, if i passes posts_per_page = -1, it shows all posts.
Please help me to run pagination, thank you very much in advance.
I think you are using a plugin for display the pagination, is better to create your custome pagination.
In your function.php write this code:
if ( ! function_exists( 'your_paging_nav' ) ) :
function your_paging_nav() {
global $wp_query;
// Don't print empty markup if there's only one page.
if ( $wp_query->max_num_pages < 2 )
return;
?>
<nav>
<h1><?php _e( 'Posts navigation', 'framwork-translation' ); ?></h1>
<div>
<?php if ( get_next_posts_link() ) : ?>
<div class="nav-previous"><?php next_posts_link( __( 'Older posts', 'framwork-translation' ) ); ?></div>
<?php endif; ?>
<?php if ( get_previous_posts_link() ) : ?>
<div class="nav-next"><?php previous_posts_link( __( 'Newer posts', 'framwork-translation' ) ); ?></div>
<?php endif; ?>
</div>
</nav>
<?php
}
endif;
and in index.php
<body <?php body_class(); ?>>
<?php get_header(); ?>
<div class="primary">
<?php if ( have_posts() ) : ?>
<!-- The loop -->
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>
<?php your_paging_nav(); ?>
<?php else : ?>
<?php get_template_part( 'content', 'none' ); ?>
<?php endif; ?>
</div>
<?php get_footer(); ?>

All posts on page of one category

I really can't figure this out. I'm trying to have posts all posts on a page from one category, but I still get all categories. This is the code I'm using now. I thought I could manage with WP_Query( array( 'posts_per_page' => -1, 'category_name' => 'resep' ) );, but it totally drives me nuts.
<?php /* Template Name: Blog */ ?>
<?php get_header(); ?>
<div id="content-wrap">
<div id="content">
<div class="post_content">
<h1 class="archive_title"><?php the_title(); ?></h1>
<?php
$query['post_type'] = 'post';
// WP 3.0 PAGED BUG FIX
if ( get_query_var('paged') )
$paged = get_query_var('paged');
elseif ( get_query_var('page') )
$paged = get_query_var('page');
else
$paged = 1;
//$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$query['paged'] = $paged;
$recipe_posts = new WP_Query( array( 'posts_per_page' => -1, 'category_name' => 'resep' ) );
while ( $recipe_posts->have_posts() ) { $recipe_posts->the_post(); }
query_posts($query);
if (have_posts()) : ?>
<?php $more = 0; ?>
<div class="posts">
<?php while (have_posts()) : the_post();
$is_recipe = in_category('Resep'); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class('clearfix'); ?>>
<?php if (option::get('index_thumb') == 'on') {
get_the_image( array( 'size' => 'loop', 'width' => option::get('thumb_width'), 'height' => option::get('thumb_height'), 'before' => '<div class="post-thumb">', 'after' => '</div>' ) );
} ?>
<div class="details">
<h2 class="title"><?php the_title(); ?></h2>
<?php if ( option::get('display_meta') == 'on' ) { ?>
<div class="meta">
<?php
if ( $is_recipe ) {
$fields = get_fields();
if ( !empty( $fields ) ) echo $fields;
} else { ?>
<p><strong><img src="<?php echo get_template_directory_uri() . '/images/person.png'; ?>" /><?php _e('Author', 'wpzoom'); ?>:</strong><?php the_author_posts_link(); ?></p>
<p><strong><img src="<?php echo get_template_directory_uri() . '/images/clock.png'; ?>" />
<?php _e('Posted', 'wpzoom'); ?>
:</strong> <?php echo get_the_date(); ?></p>
<?php } ?>
</div>
<?php } ?>
<div class="entry">
<?php the_content('<span>'.__('Read More', 'wpzoom').' ›</span>'); ?>
</div>
<p>
<?php if ( option::get('display_readmore') == 'on' && (option::get('display_content') == 'Excerpt') ) { ?>
<a href="<?php the_permalink(); ?>" class=" clean more-link">
<?php _e( ( $is_recipe ? 'Lihat Resep' : 'Read More' ), 'wpzoom' ); ?>
</a>
<?php } ?>
<?php edit_post_link( __('Edit', 'wpzoom'), ' <small>', '</small>' ); ?>
</p>
</div>
<div class="cleaner"> </div>
</div>
<!-- /.post -->
<?php endwhile; ?>
</div>
<div class="cleaner"> </div>
<?php get_template_part( 'pagination' ); ?>
<?php wp_reset_query(); ?>
<div class="cleaner"> </div>
<?php endif; ?>
</div><!-- / .post_content -->
</div><!-- / #content -->
<?php get_sidebar(); ?>
</div>
<?php get_footer(); ?>
You're making it far too complex, just specificy the stuff you need inside the while loop:
$recipe_posts = new WP_Query( array( 'posts_per_page' => -1, 'category_name' => 'resep' ) );
while ( $recipe_posts->have_posts() ) {
$recipe_posts->the_post();
echo '<li>' . get_the_title() . '</li>';
}
wp_reset_query();
You have entered loop inside loop, try this following with cleaning your code:
$args = array('posts_per_page' => -1 , 'category_name' => 'resep');
$recipe_posts = new WP_Query($args);
if($recipe_posts->have_posts()) :
while($recipe_posts->have_posts()) :
$recipe_posts->the_post();
?>
<h1><?php the_title() ?></h1>
<div class='post-content'><?php the_content() ?></div>
<?php
endwhile;
else:
?>
Oops, there are no posts.
<?php
endif;
?>
I cleaned the whole template, but posts from other categories were still there. In the end I managed with these lines
global $wp_query;
$args = array_merge( $wp_query->query, array( 'category_name' => 'resep' ) );
query_posts( $args );
$recipe_posts = new WP_Query($args);
$more = 0;
if($recipe_posts->have_posts()) :
while ($recipe_posts->have_posts()) : $recipe_posts->the_post();?>

Resources