WordPress search results only showing if admin is logged in - wordpress

WordPress search results only showing if admin is logged in.
I tried deactivating plug-ins and that didn't work. Here is the code from the search.php file (below). Not sure if this is where the problem could be or somewhere else.
If it is in the function.php file:
<?php
/**
* The template for displaying search results pages.
*
* #link https://developer.wordpress.org/themes/basics/template-hierarchy/#search-result
*
* #package Wowmall
*/
get_header();
$col = 'col-xl-12';
$post_col = 'col-xl-3 col-lg-4 col-md-6 col-sm-12 col-xs-12';
$template = '';
global $wp_query,$wowmall_options;
if( ! empty( $wowmall_options['blog_layout_type'] ) && ! in_array( $wowmall_options['blog_layout_type'], array( 'grid', 'masonry' ) ) ) {
$col = 'col-xl-10 col-lg-9 col-md-8';
$post_col = 'col-xs-12';
$template = '-list';
}
?>
<div class="container">
<header class=page-header>
<h1 class="page-title page-title-search"><?php printf( esc_html__( 'Search Results for %s', 'wowmall' ), '<span class=wowmall-search-query-title>'' . get_search_query() . ''</span>' ); ?></h1>
</header><!-- .page-header -->
<div class="row">
<main id=primary class="content-area site-main <?php echo esc_attr( $col ); ?>">
<?php if ( have_posts() ) : ?>
<div class="page-content">
<div class="row posts-<?php echo count( $wp_query->posts ); ?>">
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<div class="<?php echo esc_attr( $post_col ); ?>">
<?php
/**
* Run the loop for the search to output the results.
* If you want to overload this in a child theme then include a file
* called content-search.php and that will be used instead.
*/
get_template_part( 'template-parts/content', '' );
?>
</div>
<?php endwhile; ?>
</div>
</div>
<?php the_posts_pagination( array(
'prev_text' => '<i class=myfont-left-open-2></i>',
'next_text' => '<i class=myfont-right-open-2></i>',
'type' => 'list',
) ); ?>
<?php else : ?>
<?php get_template_part( 'template-parts/content', 'none' ); ?>
<?php endif; ?>
</main>
<?php get_sidebar(); ?>
</div>
</div>
<?php get_footer(); ?>

Related

Problem with displaying wooccomerce related products

Bello my singleproduct.php, but my related products not shown on all categories, some work and some no, it is depend on query and fonts. For example here is work https://avestone.ru/product-category/nashi-raboti/, but if I change name of category it will not work. And it does not work at all at any russian named category.
<?php
/**
* The Template for displaying all single products
*
* This template can be overridden by copying it to yourtheme/woocommerce/single-product.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
* the readme will list any important changes.
*
* #see https://docs.woocommerce.com/document/template-structure/
* #package WooCommerce\Templates
* #version 1.6.4
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
get_header(); ?>
<div class="popup_form" id="popup_form_product">
<div class="popup_form_content" id="popup_form_content_product">
<a href="javascript:PopUpHide()" class="popup_close">
<svg width="22" height="22" viewBox="0 0 22 22" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M17.1875 4.8125L4.8125 17.1875" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M17.1875 17.1875L4.8125 4.8125" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
</a>
<div class="form_title">Заказать расчет</div>
<?php echo do_shortcode( '[contact-form-7 id="6241" title="Попап товары"]' ); ?>
</div>
</div>
<?php
/**
* woocommerce_before_main_content hook.
*
* #hooked woocommerce_output_content_wrapper - 10 (outputs opening divs for the content)
* #hooked woocommerce_breadcrumb - 20
*/
do_action( 'woocommerce_before_main_content' );
?>
<div id="product-<?php the_ID(); ?>" <?php wc_product_class( '', $product ); ?>>
<div class="product_content">
<div class="breadcrumb">
<?php $values = get_the_terms( $product->id, 'pa_brend'); ?>
<ul>
<li>Каталог</li>
<li> - </li>
<li>
<?php foreach ( $values as $value ) {
echo '' . $value->name .'';
} ?></li>
<li> - </li>
<li><?php the_title(); ?></li>
</ul>
</div>
<?php the_title( '<h1 class="product_title mobile-product_title">', '</h1>' ); ?>
<?php while ( have_posts() ) : ?>
<?php the_post(); ?>
<div class="product_top_content">
<div class="product_top_content_block">
<div class="product_img">
<?php
$columns = apply_filters( 'woocommerce_product_thumbnails_columns', 4 );
$post_thumbnail_id = $product->get_image_id();
$wrapper_classes = apply_filters(
'woocommerce_single_product_image_gallery_classes',
array(
'woocommerce-product-gallery',
'woocommerce-product-gallery--' . ( $post_thumbnail_id ? 'with-images' : 'without-images' ),
'woocommerce-product-gallery--columns-' . absint( $columns ),
'images',
)
);
?>
<div class="<?php echo esc_attr( implode( ' ', array_map( 'sanitize_html_class', $wrapper_classes ) ) ); ?>" data-columns="<?php echo esc_attr( $columns ); ?>" style="opacity: 0; transition: opacity .25s ease-in-out;">
<figure class="woocommerce-product-gallery__wrapper">
<?php
if ( $post_thumbnail_id ) {
$html = wc_get_gallery_image_html( $post_thumbnail_id, true );
} else {
$html = '<div class="woocommerce-product-gallery__image--placeholder">';
$html .= sprintf( '<img src="%s" alt="%s" class="wp-post-image" />', esc_url( wc_placeholder_img_src( 'woocommerce_single' ) ), esc_html__( 'Awaiting product image', 'woocommerce' ) );
$html .= '</div>';
}
echo apply_filters( 'woocommerce_single_product_image_thumbnail_html', $html, $post_thumbnail_id ); // phpcs:disable WordPress.XSS.EscapeOutput.OutputNotEscaped
do_action( 'woocommerce_product_thumbnails' );
?>
</figure>
</div>
</div>
</div>
<div class="product_top_content_block product_top_content_block_right">
<?php the_title( '<h1 class="product_title">', '</h1>' ); ?>
<ul class="product_atr">
<li>Категория: <?php $cats_arr = wc_get_product_category_list( $product->get_id()); $cat_arr = explode(",", $cats_arr); echo $cat_arr[0];?></li>
<?php echo $product->list_attributes(); ?>
<li><?php esc_html_e( 'SKU:', 'woocommerce' ); ?> <span><?php echo $product->get_sku(); ?><span></li>
</ul>
<?php if( $product->get_price_html()) { ?>
<div class="product_price">
<p class="<?php echo esc_attr( apply_filters( 'woocommerce_product_price_class', 'price' ) ); ?>"><span><?php echo $product->get_price_html(); ?></span> РУБ / м2</p>
<div class="single_product_text">Cтоимость за квадратный метр материала, без учета стоимости изготовления, доставки и монтажа изделия</div>
</div>
<?php } ?>
<form class="product_price_cart cart" action="<?php echo esc_url( apply_filters( 'woocommerce_add_to_cart_form_action', $product->get_permalink() ) ); ?>" method="post" enctype='multipart/form-data'>
<?php do_action( 'woocommerce_before_add_to_cart_button' ); ?>
<div class="single_product_btn">
Расчитать стоимость
</div>
</form>
</div>
</div>
<?php $the_content = apply_filters( 'the_content', get_the_content() ); ?>
<div class="product_text_container">
<div class="product_text_tabs">
<?php if ( ! empty( $the_content ) ) : ?>
<div class="product_text_tab_title tab_1 active">Описание</div>
<?php endif; ?>
<?php if( have_rows('reviews') ): ?>
<div class="product_text_tab_title tab_2 <?php if ( empty( $the_content ) ) echo 'active'; ?>">Отзывы <span class="count"></span></div>
<?php endif; ?>
</div>
<div class="product_text_tabs_content">
<div class="product_text text_tab_1 active">
<?php the_content(); ?>
</div>
<div class="product_text text_tab_2 <?php if ( empty( $the_content ) ) echo 'active'; ?>">
<div class="product_text_review_container">
<?php
$count=1;
if( have_rows('reviews') ):
while ( have_rows('reviews') ) : the_row(); ?>
<div class="product_review_block">
<div class="product_review_block_left">
<?php if( get_sub_field('doc') ): ?>
<div class="product_review_title"><?php the_sub_field('doc'); ?></div>
<?php endif; ?>
<ul class="product_review_list">
<?php if( get_sub_field('client') ): ?>
<li>Заказчик: <?php the_sub_field('client'); ?></li>
<?php endif; ?>
<?php if( get_sub_field('adress') ): ?>
<li>Адрес: <?php the_sub_field('adress'); ?></li>
<?php endif; ?>
<?php if( get_sub_field('stone') ): ?>
<li>Камень: <?php the_sub_field('stone'); ?></li>
<?php endif; ?>
<?php if( get_sub_field('price') ): ?>
<li>Стоимость: <?php the_sub_field('price'); ?></li>
<?php endif; ?>
</ul>
<div class="product_review_text product_review_text-<? echo $count?>">
<?php if( get_sub_field('text') ): ?>
<div class="product_review_text_title">Текст:</div>
<p><?php the_sub_field('text'); ?></p>
Показать весть текст
<?php endif; ?>
</div>
</div>
<div class="product_review_block_right">
<?php if( have_rows('gallery') ): ?>
<div class="slider-review-for">
<?php while( have_rows('gallery') ): the_row();?>
<div class="slider-review-for-box"><img src="<?php echo get_sub_field('img'); ?>" alt="<?php echo $image['alt']; ?>"></div>
<?php endwhile; ?>
</div>
<div class="slider-review-nav">
<?php while( have_rows('gallery') ): the_row();?>
<div class="slider-review-nav-box"><img src="<?php echo get_sub_field('img'); ?>" alt="<?php echo $image['alt']; ?>"></div>
<?php endwhile; ?>
</div>
<?php endif; ?>
</div>
</div>
<?php
$count++;
endwhile;
endif;
?>
<div class="product_text_review_container_btn">Показать все отзывы</div>
</div>
</div>
</div>
</div>
<?php endwhile; // end of the loop. ?>
<?php
$cats_arr = wc_get_product_category_list( $product->get_id()); $cat_arr = explode(",", $cats_arr); $cat = $cat_arr[0]; $mycat = preg_replace('#<a.*?>|</a>#sui', '', $cat);
$id5 = get_the_ID();
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'posts_per_page' => 4,
'orderby' => 'rand',
'post__not_in' => array($id5),
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'terms' => $mycat,
'field' => 'slug',
),
)
);
$loop = new WP_Query($args);
if ($loop->have_posts())
{ ?>
<div class="relative_products">
<h2>Похожие камни:</h2>
<div class="relative_products_container">
<div class="woocommerce columns-4 ">
<ul class="products oceanwp-row clr grid">
<?php
while ($loop->have_posts()):
$loop->the_post(); ?>
<li class="entry has-media col span_1_of_4 owp-content-left owp-thumbs-layout-horizontal owp-btn-normal owp-tabs-layout-horizontal product type-product post-5856 status-publish first instock product_cat-classical product_cat-95 has-post-thumbnail shipping-taxable purchasable product-type-simple">
<div class="product-inner clr">
<div class="woo-entry-image clr">
<?php if (has_post_thumbnail()): ?>
<img src="<?php the_post_thumbnail_url('large'); ?>" alt="<?php the_title(); ?>">
<?php endif; ?>
</div><!-- .woo-entry-image -->
<ul class="woo-entry-inner clr">
<li class="image-wrap">
<div class="woo-entry-image clr">
<?php if (has_post_thumbnail()): ?>
<img src="<?php the_post_thumbnail_url('large'); ?>" alt="<?php the_title(); ?>">
<?php endif; ?>
</div><!-- .woo-entry-image -->
</li>
<li class="title"><?php the_title(); ?></li>
<li class="category">Категория <?php $cats_arr = wc_get_product_category_list( $product->get_id()); $cat_arr = explode(",", $cats_arr); echo $cat_arr[0];?></li>
</ul>
</div>
</li>
<?php
endwhile; ?>
</ul>
</div>
</div>
</div>
<?php } ?>
<?php
/**
* woocommerce_after_main_content hook.
*
* #hooked woocommerce_output_content_wrapper_end - 10 (outputs closing divs for the content)
*/
do_action( 'woocommerce_after_main_content' );
?>
<?php
get_footer();
/* Omit closing PHP tag at the end of PHP files to avoid "headers already sent" issues. */
I tried several solutions, tried to make it work via plugin, nothing help.

FacetWP is braking masonry layout

I'm using FacetWP to build a filter form. Unfortunately, my masonry layout is braking when I select any option in the form. Results are presenting as a single column, instead of 3. Weird is that F5 makes the order (3 columns) right.
I was trying to use these methods: https://facetwp.com/documentation/template-configuration/ and this one: https://facetwp.com/using-facetwp-with-existing-template-files/
My code is
<div id="primary" class="content-area col-md-9 <?php echo sydney_blog_layout(); ?>">
<main id="main" class="post-wrap" role="main">
<?php
$args = array(
'post_type' => 'nieruchomosci',
'posts_per_page' => 12,
);
$query = new WP_Query( $args );?>
<?php if ( $query->have_posts() ) : ?>
<header class="page-header">
<h3 class="archive-title">Szukaj nieruchomości</h3>
</header><!-- .page-header -->
<div class="wyszukiwarka"><?php echo facetwp_display( 'facet', 'rodzaj' ); ?><?php echo facetwp_display( 'facet', 'typ' ); ?><?php echo facetwp_display( 'facet', 'lokalizacja' ); ?></div>
<div class="posts-layout facetwp-template">
<?php while ( $query->have_posts() ) : $query->the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php if ( has_post_thumbnail() && ( get_theme_mod( 'index_feat_image' ) != 1 ) ) : ?>
<div class="entry-thumb">
<?php the_post_thumbnail('sydney-large-thumb'); ?>
</div>
<?php endif; ?>
<header class="entry-header">
<?php the_title( sprintf( '<h2 class="title-post entry-title">', esc_url( get_permalink() ) ), '</h2>' ); ?>
</header><!-- .entry-header -->
<div class="entry-post">
<?php the_field('cena'); ?> PLN | <?php the_field('powierzchnia'); ?> m<sup>2</sup></br>
<?php echo get_the_term_list( $post->ID, 'rodzaj', '', ', ', '' ) ?> na <?php echo get_the_term_list( $post->ID, 'typ', '', ', ', '' ) ?> w miejscowości <?php echo get_the_term_list( $post->ID, 'lokalizacja', '', ', ', '' ) ?>
<?php
wp_link_pages( array(
'before' => '<div class="page-links">' . __( 'Pages:', 'sydney' ),
'after' => '</div>',
) );
?>
</div><!-- .entry-post -->
<footer class="entry-footer">
<?php sydney_entry_footer(); ?>
</footer><!-- .entry-footer -->
</article><!-- #post-## -->
<?php endwhile; ?>
</div>
<?php the_posts_navigation(); ?>
<?php else : ?>
<?php get_template_part( 'content', 'none' ); ?>
<?php endif; ?>
</main><!-- #main -->
</div><!-- #primary -->
Any advice will be very nice.
Actually I got his to work (using Masonry PACKAGED v4.1.1 & imagesLoaded PACKAGED v3.1.8):
$(document).on('facetwp-loaded', function() {
var $grid = $( '.grid' ).imagesLoaded( function() {
$grid.masonry("reloadItems");
$grid.masonry( {
itemSelector : '.loop-entry',
gutter : 30,
columnWidth : 240,
isAnimated : true,
animationOptions : {
duration : 300,
easing : 'easeInOutCirc',
queue : false
}
});
});
});
Try reload layout on facetwp-loaded event. From your question it is unclear how a masonry layout was created. Assuming it is masonry.js, you can do layout when FacetWP finishes loading like this:
$(document).on('facetwp-loaded', function() {
// do layout when FacetWP finishes
$grid.masonry('layout');
});
Check more here
https://facetwp.com/documentation/facetwp-loaded/

Making text appear above the static picture slider on the Alt homepage, with static slider template on Wordpress

Basically I'm making a site on Wordpress using the Wordpress theme "Restaurateur". As you can see on the demo home page here http://wprestaurateur.com/ using the Alt homepage with static slider template, below the navigation is the picture slider and then below that some text. I've basically completed the site except I want the text to show up first and then have the picture slider below it. I've tried all I can think of with no luck. Any suggestions? Thanks.
EDIT: Added the .php file for the template im using for the home page.
<div id="content" class="clearfix">
<div id="main" class="clearfix sldr" role="main">
<div id="slide-wrap">
<?php if ( have_posts() ) : ?>
<div id="load-cycle"></div>
<div class="cycle-slideshow alt-static" <?php
if ( get_theme_mod('restaurateur_slider_effect') ) {
echo 'data-cycle-fx="' . wp_kses_post( get_theme_mod('restaurateur_slider_effect') ) . '" data-cycle-tile-count="10"';
} else {
echo 'data-cycle-fx="scrollHorz"';
}
?> data-cycle-slides="> div.slides" <?php
if ( get_theme_mod('restaurateur_slider_timeout') ) {
$slider_timeout = wp_kses_post( get_theme_mod('restaurateur_slider_timeout') );
echo 'data-cycle-timeout="' . $slider_timeout . '000"';
} else {
echo 'data-cycle-timeout="3000"';
}
?> >
<div class="cycle-pager"></div>
<?php while ( have_posts() ) : the_post(); ?>
<?php if ( has_shortcode( $post->post_content, 'gallery' ) ) : ?>
<?php
$gallery = get_post_gallery( $post, false );
$ids = explode( ",", $gallery['ids'] );
$hasgallery = 1;
foreach( $ids as $id ) {
$title = get_post_field('post_title', $id);
$meta = get_post_field('post_excerpt', $id);
$link = wp_get_attachment_url( $id );
$image = wp_get_attachment_image( $id, array( 1000, 640 ));
?>
<div class="slides">
<div id="post-<?php the_ID(); ?>" <?php post_class('post-theme'); ?>>
<div class="slide-thumb"><?php echo $image; ?></div>
</div>
</div><!-- .slides -->
<?php } ?>
<?php else : ?>
<?php
$args = array(
'post_type' => 'attachment',
'numberposts' => -1,
'post_status' => null,
'post_parent' => $post->ID,
'orderby' => 'menu_order',
'order' => 'ASC'
);
$attachments = get_posts( $args );
if ( $attachments ) {
foreach ( $attachments as $attachment ) { ?>
<div class="slides">
<div id="post-<?php the_ID(); ?>" <?php post_class('post-theme'); ?>>
<div class="slide-thumb"><?php echo wp_get_attachment_image( $attachment->ID, array( 1000, 640 ), false, '' ); ?></div>
</div>
</div>
<?php }
} else {
?>
<div class="no-slide-image"><?php _e('Images added to this page will appear here', 'restaurateur'); ?></div>
<?php
} ?>
<?php endif; ?>
<?php endwhile; ?>
</div>
<?php endif; ?>
</div>
<?php $content = restaurateur_content(9999); ?>
<?php $content = preg_replace(array('{<a[^>]*><img}','{/></a>}'), array('<img','/>'), $content); ?>
<?php $content = preg_replace('/<img[^>]+./', '', $content); ?>
<?php $content = preg_replace('#<p>\s*+(<br\s*/*>)?\s*</p>#i', '', $content); ?>
<div class="intro-content">
<?php echo $content; ?>
</div>
</div> <!-- end #main -->
</div> <!-- end #content -->
Well we need to see the php file for your homepage to be able to help. But there will be a function that calls the slider, and you'll need to move it below the text content area. Or you can just add some text ahead of that slider function yourself.

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