Wordpress not showing posts older than 2 days - wordpress

I am recently experiencing a very odd bug.
I have created some custom fields for my posts and just realized that posts older than 2 days don't show anymore...if I change the date to yesterday or today, they reappear...
Here's the code I wrote to show my posts:
<?php
$partnersId=array();
$argSections = array(
'posts_per_page' => -1,
'post_type' => 'post',
'orderby' => 'date',
'category' => '38',
'order' => 'DESC'
);
$postsSections = get_posts($argsSections);
foreach ($postsSections as $postSections):
setup_postdata($postSections);
$idPartner = $postSections->ID; ?>
<div class="row box_agenda_filter" data-filter="<?php echo get_field('section_filter_',$idPartner); ?>">
<div class="event_time event_time_red">
<span><?php echo get_field('partner_type_',$idPartner); ?></span>
</div>
<div class="info_text pseudo_element">
<img src="<?php echo get_field('partner_logo_',$idPartner); ?>" style="width:200px; height:auto; position:relative; margin:20px 0;"/>
<div class="clear"></div>
<?php echo get_the_content($idPartner); ?>
</div>
</div>
<?php endforeach; ?>

Related

WoCoommerce: get bundle data items product in custom loop

I have a pizza sales site which offers 'Ingredients' of which these are simple products, for example: Pizza NapolĂ­ is a bundle product, this product has ingredients grouped together.
What I'm looking for is to show in a custom loop (wp_query) the children products or ingredients of this pizza, which are 'Cheese(Queso)', 'Bacon(Tocineta)', etc.
Images reference here:
My code:
<?php
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'ignore_sticky_posts' => 1,
'orderby' => 'date',
'order' => 'ASC',
'meta_key' => '_stock_status',
'posts_per_page' => 10,
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'terms' => array('pizzas'),
'field' => 'name',
'operator' => 'IN'
)
)
);
// End query
$products = new WP_Query( $args, 'woocommerce'); ?>
<div class="menu-grid-pizzas">
<?php if ($products->have_posts()): ?>
<div class="container">
<ul class="grid-pizzas-list">
<?php while ($products->have_posts()): $products->the_post(); ?>
<li class="grid-pizzas-content">
<div class="content-left">
<div class="grid-img">
<a href="<?php the_permalink();?>">
<?php the_post_thumbnail('medium');?>
</a>
</div>
</div>
<div class="content-right">
<div class="grid-product-title">
<a href="<?php the_permalink();?>">
<h4><?php the_title();?></h4>
</a>
</div>
<div class="grid-product-content">
<?php $content = get_the_content();?>
<p><?php echo mb_strimwidth($content, 0, 120, "...");?></p>
</div>
<div class="grid-product-ingredints">
<!-- HERE get DATA items bundles -->
</div>
<div class="grid-product-price">
<?php $precio = get_post_meta( get_the_ID(), '_price', true );?>
<p><?php echo wc_price( $precio ); ?></p>
</div>
<div class="grid-product-add-to-card">
<?php do_action('woocommerce_after_shop_loop_item' , 'woocommerce_template_loop_add_to_cart' , 10 );?>
</div>
</div>
</li>
<?php endwhile;?>
<?php wp_reset_postdata();?>
</ul>
</div>
<?php endif;?>
</div>
As you can see, it is a custom loop from which I call all products with the category 'Pizza' with a wp_query.
I hope you can help me, thank you.

Can't display custom post type categories on the page

I have a custom post type called "case_studies" and it has 3 categories: "seo", "website-design" and "facebook-advertising".
I have several posts in the main page, and for each post I want to output what categories the post has.
For example, the latest post has a category of "seo" and "facebook-advertising", and I want it to be displayed in the page.
I have tried the get_the_terms(); function but I think I am using it incorrectly.
Here is the code of the page:
<div class="container">
<!--
<div class="category_container">
<p class="category_item" id="all">All</p>
<p class="category_item" id="website">Websites</p>
<p class="category_item" id="facebook">Facebook Ads</p>
<p class="category_item" id="seo">SEO</p>
</div>
-->
<div class="row d-flex">
<?php
$args1 = array( 'post_type' => array('case_studies'), 'order' => 'DESC', 'posts_per_page' => 30, 'orderby' => 'date' );
$loop = new WP_Query( $args1 );
while ( $loop->have_posts() ) {
$loop->the_post();
$feat_image = wp_get_attachment_url( get_post_thumbnail_id($loop->ID));
?>
<div class="col-sm-4">
<div class="case-study-content">
<a href="<?php the_permalink() ?>" class="blog_blocks">
<div class="b_image">
<img src="<?php echo get_the_post_thumbnail_url(); ?>"/>
</div>
<div class="b_h_sec">
<h2><?php the_title(); ?></h2>
<p><?php echo wp_strip_all_tags( get_the_excerpt(), true ); ?></p>
<span class="r_m">Read More</span>
</div>
</a>
</div>
</div>
<?php } ?>
<?php wp_reset_postdata(); ?>
</div>
</div>
Here is how the output looks right now and where I want categories to be displayed.

Unable to reset post data in wordpress custom query

Edit - I already tried wp_reset_query() it doesn't work, the first loop executes as intended but the second loop just jumps to the else and I get not working
I am using 2 custom WP_Query loops in one page, the first is to get posts from a certain category, and the second is just getting the posts by dates,
here's the code
<?php
$args = array(
'post_type' => 'post',
'post_status' => 'any',
'category' => 3,
'posts_per_page' => 4);
$wpdb = new WP_Query($args);
if ($wpdb->have_posts()):
while ($wpdb->have_posts()):
$wpdb->the_post(); ?>
<div class="patta p-4 col-lg-3 col-md-6">
<!-- FIX THIS -->
<img class="card-img-top"
src="<?php the_post_thumbnail(); ?>"
alt="<?php the_post_thumbnail_caption() ?>"/>
<h4><b><?php the_title(); ?></b><br></h4>
<p>
Link
</p>
</div>
<?php
endwhile;
wp_reset_postdata();
endif;
?>
second loop
<?php
$args = array(
'post_type' => 'post',
'post_status' => 'any',
'orderby' => 'post_date',
'order' => 'DESC',
'posts_per_page' => 4);
$wpdb = new WP_Query($args);
if ($wpdb->have_posts()):
while ($wpdb->have_posts()):
$wpdb->the_post(); ?>
<div class="patta p-4 col-lg-3 col-md-6">
<!-- FIX THIS -->
<img class="card-img-top"
src="<?php if (the_post_thumbnail()): the_post_thumbnail(); else:echo 'https://lamasec.pythonanywhere.com/static/img/vulnhub.png';endif; ?>"
alt="<?php the_post_thumbnail_caption() ?>"/>
<h4><b><?php the_title(); ?></b><br></h4>
<p>
Link
</p>
</div>
<?php
endwhile;
wp_reset_postdata();
else: echo 'not working';
endif;
?>
I am using wp_reset_postdata(); but it doesn't seem to be working.
You should also use:
wp_reset_query()
After reading the documentation for multiple loops in one page here, I only had one WP_Query for both the loops. I stored the ID's of all the posts from the desired category and check for them in the second loop and continue over them. Here's the final code -
first loop
<?php
$args = array(
'post_type' => 'post',
'post_status' => 'any',
'category' => 3,
'posts_per_page' => 4);
$wpdb = new WP_Query($args);
if ($wpdb->have_posts()):
while ($wpdb->have_posts()):
$wpdb->the_post();
$do_not_duplicate[] = $post->ID; ?>
<div class="patta p-4 col-lg-3 col-md-6">
<!-- FIX THIS -->
<img class="card-img-top"
src="<?php the_post_thumbnail(); ?>"
alt="<?php the_post_thumbnail_caption() ?>"/>
<h4><b><?php the_title(); ?></b><br></h4>
<p>
Link
</p>
</div>
<?php endwhile; ?>
Second Loop
if (have_posts()):
while (have_posts()):
the_post();
if (in_array($post->ID, $do_not_duplicate)) continue;
?>
<div class="patta p-4 col-lg-3 col-md-6">
<!-- FIX THIS -->
<img class="card-img-top"
src="<?php the_post_thumbnail(); ?>"
alt="<?php the_post_thumbnail_caption() ?>"/>
<h4><b><?php the_title(); ?></b><br></h4>
<p>
Link
</p>
</div>
<?php
endwhile;
endif;
endif;
?>

wordpress outputting extra html code

I'm building a theme in WordPress, I'm a newbie, along with the image HTML is being outputted, please do help me resolve this issue, thank you.
<?php
$args = array( 'numberposts' => 4, 'order'=> 'ASC', 'orderby' => 'title', 'category' => '5' );
$postslist = get_posts( $args );
foreach ($postslist as $post) : setup_postdata($post); ?>
<li>
<div class="timeline-image">
<a href="<?php the_permalink(); ?>">
<img class="rounded-circle img-fluid" src="<?php echo the_post_thumbnail(); ?>">
</a>
</div>
<div class="timeline-panel">
<div class="timeline-heading">
<h4 class="subheading text-left"><?php the_title(); ?></h4>
</div>
<div class="timeline-body">
<p class="text-muted text-justify"><?php the_excerpt(); ?>
Read More >>
</p>
</div>
</div>
</li>
<?php endforeach; ?>
You should be looping through the posts as such and not using foreach:
<?php
$args = array(
'post_type' => 'post',
'posts_per_page' => 4,
'orderby' => 'title',
'order' => 'ASC',
'category__in' => 5
);
$loop = new wp_query( $args );
while( $loop->have_rows() ) : $loop->the_row();
?>
Your article content…
<h4 class="subheading text-left"><?php the_title(); ?></h4>
<?php endif; ?>
If you need to loop through a different custom post types, use this guide.

WPquery + add row every nth element

So the case if following - i've got a wpquery like on the code below.
<section class="row service_block_row bgf" id="page-<?php the_ID(); ?>">
<div class="container">
<div class="row">
<div class="col-sm-12">
<?php
$args = array(
'post_type' => 'page',
'posts_per_page' => -1,
'post_parent' => $post->ID,
'order' => 'ASC',
'orderby' => 'menu_order'
);
$parent = new WP_Query( $args );
if ( $parent->have_posts() ) : ?>
<?php while ( $parent->have_posts() ) : $parent->the_post(); ?>
<div class="row">
<div class="col-sm-12 col-lg-3">
<h1><?php the_title(); ?></h1>
</div>
</div>
<?php endwhile; ?>
<?php endif; wp_reset_query(); ?>
</div>
</div>
</div>
</section>
What I would like to achieve is to have the loop working like that:
<ROW>
<COL-LG-3>
<COL-LG-3>
<COL-LG-3>
<COL-LG-3>
</ROW>
SO in fact what i would lke to achieve is to have 4 elements inside row without creating different loops. I know i should use some counter but i have no clue how;/
thanks
Add new row after 4 cols
<section class="row service_block_row bgf" id="page-<?php the_ID(); ?>">
<div class="container">
<div class="row">
<div class="col-sm-12">
<?php
$args = array(
'post_type' => 'page',
'posts_per_page' => -1,
'post_parent' => $post->ID,
'order' => 'ASC',
'orderby' => 'menu_order'
);
$parent = new WP_Query( $args );
if ( $parent->have_posts() ) :
$count=0;
?>
<div class="row">
<?php while ( $parent->have_posts() ) : $parent->the_post();
$count++;
?>
<div class="col-sm-12 col-lg-3">
<h1><?php the_title(); ?></h1>
</div>
<?php
if($count%4==0)
{
echo '</div><div class="row">';
}
endwhile; ?>
</div>
<?php endif; ?>
<?php wp_reset_query(); ?>
</div>
</div>
</div>

Resources