Display the trash posts instead of published posts? - wordpress

I want to display the posts of post_status="trash" but not post_status="publish". In short, the posts in trash should get displayed on the site. For how long the trash posts would be available in trash? Any help would be appreciated.
index.php
<?php
// show all coupons and setup pagination
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts(array(
'post_type' => APP_POST_TYPE,
'ignore_sticky_posts' => 1,
'paged' => $paged
));
?>
<?php get_template_part('loop', 'coupon'); ?>
loop-coupon.php
<?php while (have_posts()) : the_post(); ?>
<?php appthemes_before_post(); ?>
<div <?php post_class('item'); ?> id="post-<?php echo $post->ID; ?>">
<div class="item-holder">
<div class="item-frame">
<div class="store-holder">
<div class="store-image">
<img height="89" width="110" src="<?php echo clpr_store_image($post->ID, APP_TAX_STORE, 'term_id', '110', null); ?>" alt="" />
</div>
<div class="store-name">
<?php echo get_the_term_list($post->ID, APP_TAX_STORE, ' ', ', ', ''); ?>
</div>
</div>
<?php clpr_vote_box_badge($post->ID, $the_trans); ?>
<div class="item-panel">
<?php clpr_coupon_code_box(); ?>
<div class="clear"></div>
<?php appthemes_before_post_title(); ?>
<h1><?php if (mb_strlen(get_the_title()) >= 87) echo mb_substr(get_the_title(), 0, 87).'...'; else the_title(); ?></h1>
<?php appthemes_after_post_title(); ?>
<?php appthemes_before_post_content(); ?>
<p class="desc"><?php echo mb_substr(strip_tags($post->post_content), 0, 200).'... ';?><a class="more" href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'View the %s coupon page', 'appthemes' ), the_title_attribute( 'echo=0' ) ); ?>"><?php _e('more ››', 'appthemes') ?></a></p>
<?php appthemes_after_post_content(); ?>
</div> <!-- #item-panel -->
</div> <!-- #item-frame -->
</div>
</div>
<?php appthemes_after_post(); ?>
<?php appthemes_after_endwhile(); ?>
<?php appthemes_loop_else(); ?>
<h3><?php _e('Sorry, no coupons found', 'appthemes'); ?></h3>
`

Try adding this before your loop
query_posts($query_string. '&post_status=trash');

Related

I can not show my product feature image

<?php
$params = array(
'posts_per_page' => 9,
'post_type' => 'product'
);
$wc_query = new WP_Query($params);
if ($wc_query->have_posts()) :
while ($wc_query->have_posts()) : $wc_query->the_post(); ?>
<div class="col-sm-4 nk">
<div class="course">
<a href="<?php the_permalink(); ?>">
<img src="<?php the_post_thumbnail('thumbnail', array('class' => 'img-responsive')); ?>" />
</a>
<h3> <?php the_title(); ?></h3>
<h5><?php the_author(); ?></h5>
<p><?php echo $product->get_rating_html();?></p>
<h4><?php echo $product->get_price_html();?></h4>
</div>
</div>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php else: ?>
<p>
<?php _e( 'No Products' ); ?>
</p>
<?php endif; ?>
First of all,
replace this code
<img src="<?php the_post_thumbnail('thumbnail', array('class' => 'img-responsive')); ?>" />
with
<?php the_post_thumbnail('thumbnail', array('class' => 'img-responsive')); ?>
And you need to add <?php global $product; ?> exactly before it use.
The total correct code is
<?php
$params = array(
'posts_per_page' => 9,
'post_type' => 'product'
);
$wc_query = new WP_Query($params);
if ($wc_query->have_posts()) :
while ($wc_query->have_posts()) : $wc_query->the_post(); ?>
<?php global $product;?>
<div class="col-sm-4 nk">
<div class="course">
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail('thumbnail', array('class' => 'img-responsive')); ?>
</a>
<h3> <?php the_title(); ?></h3>
<h5><?php the_author(); ?></h5>
<p><?php echo $product->get_rating_html();?></p>
<h4><?php echo $product->get_price_html();?></h4>
</div>
</div>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php else: ?>
<p>
<?php _e( 'No Products' ); ?>
</p>
<?php endif; ?>
you are doing mistake whenever you use the_post_thumbnail() write with echo the_post_thumbnail();
so instead of the_post_thumbnail() use echo the_post_thumbnail()

Getting multiple copies of images when using WP_query to display custom post

I'm using WP-query to display my 3 most recent 'events' which are a custom post type.
Visually it looks like its working fine, but after doing some debugging I noticed that the same image is being loaded 4 times for each post.
<div class="container">
<?php
$args = array(
'post_type' => 'projects',
'posts_per_page' => '2'
);
$the_query = new WP_Query( $args );
$count = $the_query->post_count;
?>
<div class="row small-up-1 medium-up-2 large-up-<?php echo $count ?>" data-equalizer="news" data-equalize-on-stack="false" data-equalize-on="medium">
<?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
<div class="column">
<div class="card">
<div class="card-divider" data-equalizer-watch="news">
<h4> <?php the_title(); ?></h4>
<?php
// FLEXIBLE CONTENT NAME
if( have_rows('main_sections') ):
// FLEXIBLE CONTENT NAME
while ( have_rows('main_sections') ) : the_row(); ?>
<?php // LAYOUT NAME
if( get_row_layout() == 'standard_details' ): ?>
<?php if( get_sub_field('date_of_event') ):
$field_name1 = "date_of_event";
$field1 = get_sub_field_object($field_name1);
?>
<p><?php echo $field1['value']; ?></p>
<?php endif; ?>
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>
<?php the_excerpt(__('(more…)')); ?>
</div>
<?php if ( 'video' == get_post_format() ) { ?>
<div class="video-icon">
<i class="fa fa-play fa-3x" aria-hidden="true"></i>
<?php } ?>
<a href="<?php the_permalink() ?>">
<img data-interchange="[<?php echo the_post_thumbnail_url('recent-news'); ?>, small]" alt="<?php the_title(); ?>" />
</a>
</div>
</div>
<?php
endwhile;
wp_reset_postdata();
?>
</div>
</div>
</div>

Query related posts, Wrap in Row every 3 posts

I'm trying to query some related posts and wrap them in a row div every 3 posts. I've checked all the questions regarding this but still my query renders a mess.
This is what I have so far:
<?php
$related = get_posts( array(
'category__in' => wp_get_post_categories($post->ID),
'numberposts' => 6,
'post__not_in' => array($post->ID) ) );
$counter=0;
if( $related ) foreach( $related as $post ) {
setup_postdata($post); $counter++;
?>
<div class="row">
<article class="third-width">
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" class="third-link">
<?php the_post_thumbnail('post-parrilla'); ?>
</a>
<?php exclude_post_categories("8"); ?>
<div class="clear"></div>
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" class="third-link">
<div class="post-title">
<span><?php the_title(); ?></span>
</div>
</a>
</article>
<?php if ($counter%3==0):?>
</div><div class="row">
<?php endif;?>
<?php } wp_reset_postdata(); ?>
Thank you in advance
Use below code
<?php
$related = get_posts( array(
'category__in' => wp_get_post_categories($post->ID),
'numberposts' => 6,
'post__not_in' => array($post->ID) ) );
if( $related )
{
$counter = 0;
?>
<div class="row">
<?php
foreach( $related as $post ) {
setup_postdata($post);
if ($counter%3==0){
?>
</div><div class="row">
<?php
}
?>
<article class="third-width">
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" class="third-link">
<?php the_post_thumbnail('post-parrilla'); ?>
</a>
<?php exclude_post_categories("8"); ?>
<div class="clear"></div>
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" class="third-link">
<div class="post-title">
<span><?php the_title(); ?></span>
</div>
</a>
</article>
<?php
$counter++;
}
?>
</div>
<?php
}
wp_reset_postdata();
?>

Wordpress: Recent post by tags

this is my content.php I am trying to list 2 diffrent tag on my home page. 5 post from each tag. Example 5 tags from tag:Football down of it 5 tags from tag:Basketball and here is my content.php Thanks in advance.
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php if ( has_post_thumbnail() ) : ?>
<div class="entry-thumb col-md-4 col-sm-4 col-xs-12">
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" >
<?php the_post_thumbnail('home-thumb'); ?>
</a>
</div>
<?php $has_thumb = "col-md-8 col-sm-8 col-xs-12"; ?>
<?php else : ?>
<?php $has_thumb = ""; ?>
<?php endif; ?>
<div class="entry-summary <?php echo $has_thumb; ?>">
<header class="entry-header">
<?php the_title( sprintf( '<h1 class="entry-title">', esc_url( get_permalink() ) ), '</h1>' ); ?>
</header><!-- .entry-header -->
<div class="post-info">
<?php if ( 'post' == get_post_type() ) : ?>
<?php areview_posted_on(); ?>
<?php endif; ?>
<span class="cat-link">
<?php
$category = get_the_category();
if($category[0]){
echo '<i class="fa fa-folder"></i>' . esc_attr($category[0]->cat_name) . '';
}
?>
</span>
<?php if(function_exists('yasr_get_overall_rating') && function_exists('cfs') && ($cfs->get('show_stars') == 1)) {
echo do_shortcode('[yasr_overall_rating]');
} ?>
</div>
<?php the_excerpt(); ?>
</div><!-- .entry-content -->
<div class="buttons-area">
<?php if ( function_exists('cfs') && ($cfs->get('button_link') !='' ) && ($cfs->get('button_title') !='') && ($cfs->get('button_index') == 1) ) : ?>
<?php echo esc_html($cfs->get('button_title')); ?>
<?php endif; ?>
<?php echo __('Read more', 'areview'); ?>
</div>
You should loop the tags and do a query for each one, and for each post insert your existing HTML, like this:
<?php
$tags = array(
'Football',
'Basketball'
);
foreach ($tags as $tag) {
query_posts(array(
'post_type' => 'post'
'posts_per_page' => 5,
'tax_query' => array(
'taxonomy' => 'post_tag',
'field' => 'name',
'terms' => $tag
)
));
if (have_posts()) {
while(have_posts()) {
the_post();
?>
///.... insert your existing code here
<?php
}
}
wp_reset_query();
}
?>
Just don't forget to insert your existing html instead of the ///.... insert your existing code here block.
Try this
<div class="relatedposts">
<h3>Related posts</h3>
<?php
$args=array(
'post_status' => 'publish',
'tag' => 'football,basketball', //Tag slug
'posts_per_page'=>4, // Number of related posts to display.
);
$my_query = new wp_query( $args );
while( $my_query->have_posts() ) {
$my_query->the_post();
?>
<div class="relatedthumb">
<a rel="external" href="<? the_permalink()?>"><?php the_post_thumbnail(array(150,100)); ?><br />
<?php the_title(); ?>
</a>
</div>
<?php }
wp_reset_query();
?>
</div>
Thank you everyone!! Finally I got it using this code:
get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php if ( have_posts() ) : ?>
<?php /* Start the Loop */ ?>
<div class="relatedposts">
<h3 class="widget-title">Football</h3>
<div class="decoration-bar"></div><br>
<?php
$args=array(
'post_status' => 'publish',
'tag' => 'football', //Tag slug
'posts_per_page'=>5, // Number of related posts to display.
);
$my_query = new wp_query( $args );
while( $my_query->have_posts() ) {
$my_query->the_post();
?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php if ( has_post_thumbnail() ) : ?>
<div class="entry-thumb col-md-4 col-sm-4 col-xs-12">
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" >
<?php the_post_thumbnail('home-thumb'); ?>
</a>
</div>
<?php $has_thumb = "col-md-8 col-sm-8 col-xs-12"; ?>
<?php else : ?>
<?php $has_thumb = ""; ?>
<?php endif; ?>
<div class="entry-summary <?php echo $has_thumb; ?>">
<header class="entry-header">
<?php the_title( sprintf( '<h1 class="entry-title">', esc_url( get_permalink() ) ), '</h1>' ); ?>
</header><!-- .entry-header -->
<div class="post-info">
<?php if ( 'post' == get_post_type() ) : ?>
<?php areview_posted_on(); ?>
<?php endif; ?>
<span class="cat-link">
<?php
$category = get_the_category();
if($category[0]){
echo '<i class="fa fa-folder"></i>' . esc_attr($category[0]->cat_name) . '';
}
?>
</span>
<?php if(function_exists('yasr_get_overall_rating') && function_exists('cfs') && ($cfs->get('show_stars') == 1)) {
echo do_shortcode('[yasr_overall_rating]');
} ?>
</div>
<?php the_excerpt(); ?>
</div><!-- .entry-content -->
<div class="buttons-area">
<?php if ( function_exists('cfs') && ($cfs->get('button_link') !='' ) && ($cfs->get('button_title') !='') && ($cfs->get('button_index') == 1) ) : ?>
<?php echo esc_html($cfs->get('button_title')); ?>
<?php endif; ?>
<?php echo __('Read more', 'areview'); ?>
</div>
</article>
<?php }
wp_reset_query();
?>
</div>
<center><h4 >---> More Posts <---</h4></center>
<div class="relatedposts">
<h3 class="widget-title">Basketball</h3>
<div class="decoration-bar"></div><br>
<?php
$args=array(
'post_status' => 'publish',
'tag' => 'basketball', //Tag slug
'posts_per_page'=>3, // Number of related posts to display.
);
$my_query = new wp_query( $args );
while( $my_query->have_posts() ) {
$my_query->the_post();
?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php if ( has_post_thumbnail() ) : ?>
<div class="entry-thumb col-md-4 col-sm-4 col-xs-12">
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" >
<?php the_post_thumbnail('home-thumb'); ?>
</a>
</div>
<?php $has_thumb = "col-md-8 col-sm-8 col-xs-12"; ?>
<?php else : ?>
<?php $has_thumb = ""; ?>
<?php endif; ?>
<div class="entry-summary <?php echo $has_thumb; ?>">
<header class="entry-header">
<?php the_title( sprintf( '<h1 class="entry-title">', esc_url( get_permalink() ) ), '</h1>' ); ?>
</header><!-- .entry-header -->
<div class="post-info">
<?php if ( 'post' == get_post_type() ) : ?>
<?php areview_posted_on(); ?>
<?php endif; ?>
<span class="cat-link">
<?php
$category = get_the_category();
if($category[0]){
echo '<i class="fa fa-folder"></i>' . esc_attr($category[0]->cat_name) . '';
}
?>
</span>
<?php if(function_exists('yasr_get_overall_rating') && function_exists('cfs') && ($cfs->get('show_stars') == 1)) {
echo do_shortcode('[yasr_overall_rating]');
} ?>
</div>
<?php the_excerpt(); ?>
</div><!-- .entry-content -->
<div class="buttons-area">
<?php if ( function_exists('cfs') && ($cfs->get('button_link') !='' ) && ($cfs->get('button_title') !='') && ($cfs->get('button_index') == 1) ) : ?>
<?php echo esc_html($cfs->get('button_title')); ?>
<?php endif; ?>
<?php echo __('Read more', 'areview'); ?>
</div>
</article>
<?php }
wp_reset_query();
?>
</div>
<center><h4 >---> More Posts <---</h4></center>
<div class="relatedposts">
<h3 class="widget-title">Handball</h3>
<div class="decoration-bar"></div><br>
<?php
$args=array(
'post_status' => 'publish',
'tag' => 'handball', //Tag slug
'posts_per_page'=>2, // Number of related posts to display.
);
$my_query = new wp_query( $args );
while( $my_query->have_posts() ) {
$my_query->the_post();
?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php if ( has_post_thumbnail() ) : ?>
<div class="entry-thumb col-md-4 col-sm-4 col-xs-12">
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" >
<?php the_post_thumbnail('home-thumb'); ?>
</a>
</div>
<?php $has_thumb = "col-md-8 col-sm-8 col-xs-12"; ?>
<?php else : ?>
<?php $has_thumb = ""; ?>
<?php endif; ?>
<div class="entry-summary <?php echo $has_thumb; ?>">
<header class="entry-header">
<?php the_title( sprintf( '<h1 class="entry-title">', esc_url( get_permalink() ) ), '</h1>' ); ?>
</header><!-- .entry-header -->
<div class="post-info">
<?php if ( 'post' == get_post_type() ) : ?>
<?php areview_posted_on(); ?>
<?php endif; ?>
<span class="cat-link">
<?php
$category = get_the_category();
if($category[0]){
echo '<i class="fa fa-folder"></i>' . esc_attr($category[0]->cat_name) . '';
}
?>
</span>
<?php if(function_exists('yasr_get_overall_rating') && function_exists('cfs') && ($cfs->get('show_stars') == 1)) {
echo do_shortcode('[yasr_overall_rating]');
} ?>
</div>
<?php the_excerpt(); ?>
</div><!-- .entry-content -->
<div class="buttons-area">
<?php if ( function_exists('cfs') && ($cfs->get('button_link') !='' ) && ($cfs->get('button_title') !='') && ($cfs->get('button_index') == 1) ) : ?>
<?php echo esc_html($cfs->get('button_title')); ?>
<?php endif; ?>
<?php echo __('Read more', 'areview'); ?>
</div>
</article>
<?php }
wp_reset_query();
?>
</div>
<center><h4 >---> More Posts <---</h4></center>
<?php else : ?>
<?php get_template_part( 'content', 'none' ); ?>
<?php endif; ?>
</main><!-- #main -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>

Wordpress post repeat twice at the last page

I try to display my post using two column, to make sure the fit each other, I tried to create two vertical column, and display the post odd and even seperately. Odd on left side, and even on the right side. And im suing wp_pagenavi() to get navigation working, other page work fine, display the post as I intend it to be, but on the last page, one post will repeat twice.
Here my code for the looping part
<?php if ( have_posts() ) : ?>
<?php /* Start the Loop */ ?>
<div id="holder" class="left">
<?php while ( have_posts() ) : ?>
<?php
$postcount++;
if( ($postcount % 2) == 0 ) : // skip 'even' posts
$wp_query->next_post();
else :
?>
<?php the_post(); ?>
<div class="fpost">
<div class="fposttitle">
<h1 class="left"><?php the_title(); ?></h1>
<?php if ( comments_open() || ( '0' != get_comments_number() && ! comments_open() ) ) : ?>
<div class="combox right">
<?php $x = get_comments_number(); if ($x < 10) : ?>
<?php comments_popup_link( __( '00', 'toolbox' ), __( '01', 'toolbox' ), __( '0%', 'toolbox' ) ); ?>
<?php else : ?>
<?php comments_popup_link( __( '00', 'toolbox' ), __( '01', 'toolbox' ), __( '%', 'toolbox' ) ); ?>
<?php endif; ?>
</div>
<?php endif; ?>
<div class="clear"></div>
</div>
<div class="fcontent">
<?php $thumbnail = get_post_meta(get_the_ID(), 'thumbnail', true);
if ($thumbnail) : ?>
<img src="<?php echo $thumbnail; ?>" alt="<?php the_permalink(); ?>" />
<?php else : ?>
<p><?php the_excerpt(); ?></p>
<?php endif; ?>
</div>
<div class="finfo">
<p class="left date"><?php the_time('F j, Y') ?></p>
<p class="left cat"><?php the_category(', ') ?></p>
<p class="right"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'toolbox' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark" >Read More</a></p>
<div class="clear"></div>
</div>
</div>
<?php endif; ?>
<?php endwhile; ?>
</div><!-- #content -->
<div id="holder2" class="left">
<?php while ( have_posts() ) : ?>
<?php
$postcount++;
if( ($postcount % 2) != 0 ) : // skip 'odd' posts
$wp_query->next_post();
else :
?>
<?php the_post(); ?>
<div class="fpost">
<div class="fposttitle">
<h1 class="left"><?php the_title(); ?></h1>
<?php if ( comments_open() || ( '0' != get_comments_number() && ! comments_open() ) ) : ?>
<div class="combox right">
<?php $x = get_comments_number(); if ($x < 10) : ?>
<?php comments_popup_link( __( '00', 'toolbox' ), __( '01', 'toolbox' ), __( '0%', 'toolbox' ) ); ?>
<?php else : ?>
<?php comments_popup_link( __( '00', 'toolbox' ), __( '01', 'toolbox' ), __( '%', 'toolbox' ) ); ?>
<?php endif; ?>
</div>
<?php endif; ?>
<div class="clear"></div>
</div>
<div class="fcontent">
<?php $thumbnail = get_post_meta(get_the_ID(), 'thumbnail', true);
if ($thumbnail) : ?>
<img src="<?php echo $thumbnail; ?>" alt="<?php the_permalink(); ?>" />
<?php else : ?>
<p><?php the_excerpt(); ?></p>
<?php endif; ?>
</div>
<div class="finfo">
<p class="left date"><?php the_time('F j, Y') ?></p>
<p class="left cat"><?php the_category(', ') ?></p>
<p class="right"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'toolbox' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark" >Read More</a></p>
<div class="clear"></div>
</div>
</div>
<?php endif; ?>
<?php endwhile; ?>
</div><!-- #content -->
<?php else : ?>
no post
<?php endif; ?>
<div class="clear"></div>
<div id="nav"> <?php wp_pagenavi() ?> </div>
</div><!-- #primary -->
I thinking maybe because last page, there is not enough number post, but can't figure out why the post repeat.
update: I just tried to add one new post, and everything work fine. but when I add another post, it the last page repeat same post again.
Probably should have included this as an answer instead of a comment, in the case where you have an odd number of posts, you don't reset your $postcount variable to 0, so your 2nd loop doesn't necessarily start on the same condition that the first loop did. So on your last page you're able to notice this happening, but chances are on the other pages you're skipping certain posts altogether:
<?php if ( have_posts() ) : ?>
<?php /* Start the Loop */ ?>
<div id="holder" class="left">
<?php $postcount = 0; ?>
<?php while ( have_posts() ) : ?>
<?php
$postcount++;
if( ($postcount % 2) == 0 ) : // skip 'even' posts
$wp_query->next_post();
else :
?>
<?php the_post(); ?>
<?php endif; ?>
<?php endwhile; ?>
...
</div><!-- #content -->
<div id="holder2" class="left">
<?php $postcount = 0; ?>
<?php rewind_posts();//rewind the post counter so you can do another loop ?>
<?php while ( have_posts() ) : ?>
<?php
$postcount++;
if( ($postcount % 2) != 0 ) : // skip 'odd' posts
$wp_query->next_post();
else :
?>
<?php the_post(); ?>
...
<?php endif; ?>
<?php endwhile; ?>
</div><!-- #content -->

Resources