Not able to get post data from ajax call - wordpress - php

I have an Ajax call loading more posts onto a page. Everything works and I get the HTML back from the template that I have but it's missing all the of post information so it's just the html skeleton.
I'm using the same template to load the first posts onto the page but then when using the ajax call, I can't get the Wordpress methods to display back the data.
When I var dump on my template php file, I can see all of the post information but it doesn't come through back to the inline php.
Loading the Posts:
foreach (load_posts($offset) as $post) {
include(locate_template('_includes/loop-archive-single.php'));
}
The Template:
<li>
<div class="card">
<div class="card__bd">
<div class="feature">
<div class="feature__media">
<a class="imgLink" href="<?php the_permalink(); ?>">
<img src="<?php the_field('media_image') ?>" alt="<?php the_field('media_image') ?>" />
</a>
</div>
<div class="feature__hd">
<h2 class="hdg hdg--lg">
<?php the_title(); ?>
</h2>
</div>
<div class="feature__bd">
<?php the_excerpt(); ?>
</div>
</div>
</div>
</div>
</li>
Am I outside the loop or what's going on? I'd like to keep the template that way it is right now. Again, the post data is there, but it just won't show through the_permalink() or the_field('media_image') and anything like that...

You will have to pass the ID on ajax call ... of which post you need
change the template file to
<li>
<div class="card">
<div class="card__bd">
<div class="feature">
<div class="feature__media">
<a class="imgLink" href="<?php the_permalink(); ?>">
<img src="<?php the_field('media_image',$post_ID) ?>" alt="<?php the_field('media_image',$postID) ?>" />
</a>
</div>
<div class="feature__hd">
<h2 class="hdg hdg--lg">
<?php the_title(); ?>
</h2>
</div>
<div class="feature__bd">
<?php the_excerpt($postID); ?>
</div>
</div>
</div>
</div>
</li>

Related

New to PhP and ACF (3 days in), cant get <a> to stay open

I am trying to have an ACF template which detects if the url is filled, when its filled it should turn the whole container into a link.
It looks like the tag is closed automatically (even though I dont specify this).
I am trying to keep the tag open until after the from the '.container-fluid'.
<section class="imageBlock">
<?php $url = get_sub_field('url');
if($url != null):?>
<a href="<?php $url;?>">
<?php endif;?>
<div class="container-fluid">
<div class="row align-items-center">
<div class="col-6">
<h2><?php the_sub_field('title'); ?></h2>
<p><?php the_sub_field('l_txt');?></p>
</div>
<div class="col-6">
<?php $image = get_sub_field('r_img');?>
<img src="<?php echo $image['url'];?>"/>
</div>
</div>
</div>
<?php if($url != null):?>
</a>
<?php endif;?>
</section>

How to load the next page using ajax in a WordPress loop?

I want to load page2 with AJAX in my dynamic posts loop. I searched for some possible ways and found this guide https://unicorntears.dev/snippets/load-more-posts/ but it didn't come out to be working.
I want to load the next page in the post loop by AJAX, by simply clicking a load more button.
Archive.php I am currently using is
<?php get_header(); ?>
<main class="main-content">
<div class="inner">
<?php if(have_posts()): ?>
<ul class="product-list">
<?php while(have_posts()):the_post(); ?>
<li class="list-product">
<a href="<?php the_permalink(); ?>">
<div class="product-thumbnail">
<img class="lazyload" data-src="<?php the_post_thumbnail_url(); ?>" />
</div>
<h2 class="product-title"><?php the_title(); ?></h2>
<span class="product-price"><?php if($product->is_type('variable')){echo variable_price_html();}elseif($product->is_type('simple')){echo simple_price_html();} ?></span>
</a>
</li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
</div>
</main>
<?php get_footer(); ?>
Since I am not familiar with JS, I want someone's help. Please someone help me make this happen.

database values not displaying in carousal in codeigniter php

i have a website in which i used carousel sliders to display images and its values, I have 3 carousel in my homepage, 3 of them have same code, however the first carousel is not displaying name and price like the 2nd and 3rd carousel:
as you can see in the image
the code for this carousel is below:
<section class="carousel_sec">
<div class="container">
<div class="row ">
<h3 class="carousel_heading">Trending Birthday Cakes <button class="pull-right"><span>VIEW ALL</span><!-- <span class="visible-xs">>></span> --></button></h3>
<hr>
<div class="carou">
<div class="demo">
<ul id="landing_products1">
<?php foreach($trending_products1 as $key=>$val) { ?>
<li>
<div class="item">
<div class="pad15 content_div">
<div class="carou_thumb">
<img class="st_img" src="<?php echo ADMIN_IMG.'cakes/'.$val['image'][0]['cake_image'];?>" alt="<?php echo $val['cake_name']; ?>" />
<img class="nd_img" src="<?php echo ADMIN_IMG.'cakes/'.$val['image'][0]['cake_image'];?>" alt="<?php echo $val['cake_name']; ?>" />
<p>
<?php echo $val['cake_name']; ?>
</p>
<?php
$btp_price=0;$offer_price=0;
$btp_price=$val['price'][0]['btp_price'];
$offer_price=$val['price'][0]['offer_price'];
?>
<div class="price text-center" style="width:100%;float:left;">
<span class="amount" style="color:#f2136e;font-size:14px;">
<?php echo PRICE_UNIT;?><?php echo $offer_price;?>
</span> (
<s> <?php echo $btp_price;?></s>)
<span> </span>
<br>
</div>
<!--<br><span><?php echo PRICE_UNIT;100; ?></span></p>-->
</div>
</div>
</div>
</li>
<?php } ?>
</ul>
</div>
</div>
</div>
</div>
</section>
<?php } ?>
while inspecting in browser the value is showing, the live URL is enter link description here
can anyone please tell me what could be wrong here, thanks in advance
You'll need to tweak the css to reveal the content that is hidden.
To push you in the direction, see the improvement with:
#landing_products1 {
height: 330px;
margin-top: -65px;
}
I don't know how responsive you need to be with your UI, so let's call this a temporary fix. The first carousel's dimensions don't perfectly match the others, so I'll leave the fine tuning to you.
It also appears that you have some js and css issues to mop up.

Wordpress - How to use Ajax Load More plugin

I'm developing a website in wordpress and I want to load more news when scrolling but I already have a html structure and when I put ajax load more it put own structure and I don' want that.
I'm using the Ajax Load More plugin.
So, How can I use Ajax load more with this html structure:
<?php
$posts = get_posts(['cat' => get_cat_ID("news")]);
foreach($posts as $post){
setup_postdata($post);
?>
<div class="col-xs-12 col-sm-6 col-md-4">
<a class="news-link" href="<?php the_permalink() ?>">
<div class="news">
<div class="image">
<?php the_post_thumbnail('thumbnail') ?>
<div class="mask">
<div class="icon">
<i class="icon-plus"></i>
</div>
</div>
</div>
<div class="title">
<span>
<?php the_title(); ?>
</span>
</div>
<div class="excerpt">
<p class="date">
<?php echo get_the_date('Y-m-d'); ?>
</p>
</div>
<div class="excerpt">
<p>
<?php the_excerpt(); ?>
</p>
</div>
</div>
</a>
</div>
<?php
wp_reset_postdata();
} ?>
If i put this shortcode it shows but not with the structure that i want.
[ajax_load_more id="7279302844" container_type="div" post_type="post" category="news"]
Thank you

Linking an image to the post it's associated with

I am using 'Advanced Custom Fields' and i have created an archive page to display posts from a custom post type of 'property_sales'
this is the full template
<article <?php post_class(); ?>>
<header>
<h2 class="entry-title"><?php the_title(); ?></h2>
</header>
<div class="location">
<?php the_field('location')?>
</div>
<div class="photoframe">
<img class="responsive" src="<?php the_field('property_image')?>" />
</div>
<div class="price">£
<?php the_field('price')?>
</div>
<div class="entry-summary">
<p>Added on <?php get_template_part('templates/property-meta'); ?></p>
</div>
<div class="rightmovelink">
View Full Listing
</div>
<div class="clear">
</article>
I was wondering what code I need to put in the tag in order to link to the post each image is associated with?
Try this one
<div class="photoframe">
<img class="responsive" src="<?php the_field('property_image')?>" />
</div>

Categories