@faisalahammad thank you for reply but it still didn’t work. Maybe I can share the whole codes that may be helpful.
<?php get_header(); ?>
<script>
function update_downlod_count($postid){
jQuery.ajax( {
url : '<?php echo admin_url( 'admin-ajax.php' ); ?>', // Use our localized variable that holds the AJAX URL
type: 'POST', // Declare our ajax submission method ( GET or POST )
data: { // This is our data object
action : 'update_downlod_count', // AJAX POST Action
'postid': $postid, // Replace
um_key
with your user_meta key name
'task': 'update_download'
}
} )
.success( function( results ) {
jQuery('#download_counts').html(results);
} )
.fail( function( data ) {
} );
return false; // Stop our form from submitting
}
function update_like_count($postid){
jQuery.ajax( {
url : '<?php echo admin_url( 'admin-ajax.php' ); ?>', // Use our localized variable that holds the AJAX URL
type: 'POST', // Declare our ajax submission method ( GET or POST )
data: { // This is our data object
action : 'update_downlod_count', // AJAX POST Action
'postid': $postid, // Replace um_key
with your user_meta key name
'task': 'update_count' // Replace um_key
with your user_meta key name
}
} )
.success( function( results ) {
jQuery('#download_likes').html(results);
jQuery('.bannerSpanSection__likeBtn').addClass('active');
} )
.fail( function( data ) {
} );
return false; // Stop our form from submitting
}
</script>
<div class="container">
<div class="bannerSpanSection pt-5 pb-5">
<div class="row">
<?php
if (have_posts()) {
while (have_posts()) {
the_post();
gt_set_post_view();
?>
<div class="col-12">
<div>
<h1 class="Post-title"><?php
$the_title = get_the_title();
if ( $the_title ) {
echo esc_html( the_title() );
} else {
echo 'No Title';
}
?></h1>
<?php
$posttags = get_the_tags();
$count = 0;
$max_tags = 6;
if ($posttags) {
foreach ($posttags as $tag) {
if ($count >= $max_tags) {
break;
}
$tag_link = get_tag_link($tag->term_id);
echo '<span class="tags-badge bg-dark me-1">';
echo '<a href="'.esc_url($tag_link).'" class="tag-link">'.$tag->name.'</a>';
echo '</span>';
$count++;
}
}
?>
</div><!-- heading -->
</div>
<div class="col-md-8 mb-4">
<div class="bannerSpanSection__banner">
<?php the_content(); ?>
</div><!-- Content Picture -->
<div class="custom_download_description">
<p><?php echo get_field('download_description'); ?></p>
</div>
</div><!-- Picture Description -->
<div class="col-md-4 mb-4">
<div class="bannerSpanSection__sideBarBlock rounded-2 mb-3 p-3">
<div class="row">
<div class="col-12">
<?php
$like_ip_address = get_post_meta($post->ID, 'like_ip_address');
if(!$like_ip_address){$like_ip_address[0] = array();}
$currentIp = $_SERVER['REMOTE_ADDR'];
if(in_array($currentIp, $like_ip_address[0])){
$likeactiveclass = "active";
}else{
$likeactiveclass = "";
}
$imgURL = get_the_post_thumbnail_url(get_the_ID(),'full');
if(!$imgURL){
$imgURL = get_template_directory_uri() . "/images/bg.jpg";
}
?>
<?php
$attachment_id = get_post_thumbnail_id( $post->ID );
$image_url = wp_get_attachment_url( $attachment_id );
?>
<ul class="bannerSpanSection__sideBarBtns list-unstyled d-flex align-content-center">
<li>
<a href="<?php echo esc_url( $image_url ); ?>" class="btn bannerSpanSection__donwloadBtn" download onclick="update_downlod_count(<?php echo esc_attr( $post->ID ); ?>)">
<svg fill="#000000" height="800px" width="800px" version="1.1" id="Layer_1" xmlns="https://www.w3.org/2000/svg" xmlns:xlink="https://www.w3.org/1999/xlink"
viewBox="0 0 512 512" enable-background="new 0 0 512 512" xml:space="preserve">
<path d="M442.2,186.2H302.5V0h-93.1v186.2H69.8L256,418.9L442.2,186.2z M465.5,372.4v93.1H46.5v-93.1H0V512h512V372.4H465.5z"/>
</svg>
Download
</a>
</li>
<li>
<div class="a2a_kit a2a_kit_size_32 a2a_default_style">
<a class="a2a_dd" ></a>
</div>
<script async src="https://static.addtoany.com/menu/page.js"></script>
</li>
<li><a href="javascript:void(0);" class="bannerSpanSection__likeBtn <?php echo $likeactiveclass; ?>" onclick="update_like_count(<?php echo $post->ID; ?>)"><svg version="1.1" id="Layer_1" xmlns="https://www.w3.org/2000/svg" xmlns:xlink="https://www.w3.org/1999/xlink" x="0px" y="0px"
width="606.352px" height="518.631px" viewBox="96.32 140.685 606.352 518.631"
enable-background="new 96.32 140.685 606.352 518.631" xml:space="preserve">
<g>
<path d="M154.935,396.701c-27.922-27.922-42.848-66.615-40.951-106.159c1.92-40.044,20.115-76.228,51.23-101.884
c24.104-19.865,53.939-30.367,86.273-30.367c39.77,0,78.834,16.256,107.177,44.6l28.481,28.48
c3.282,3.282,7.733,5.125,12.374,5.125c4.642,0,9.093-1.844,12.374-5.125l28.479-28.48c28.411-28.411,67.442-44.705,107.086-44.705
c32.313,0,62.179,10.539,86.37,30.476c31.182,25.848,49.377,62.161,51.197,102.217c1.79,39.389-13.231,77.95-41.211,105.793
L399.359,641.127L154.935,396.701z"/>
<path fill="#FFFFFF" d="M547.459,175.685c28.179,0,54.176,9.142,75.188,26.437c13.882,11.513,24.84,25.368,32.571,41.184
c7.41,15.158,11.558,31.43,12.327,48.367c0.77,16.933-1.88,33.509-7.873,49.266c-6.198,16.297-15.687,30.875-28.201,43.328
c-0.02,0.02-0.04,0.04-0.061,0.061L399.359,616.378l-232.05-232.051c-12.471-12.472-21.92-27.091-28.083-43.453
c-5.966-15.838-8.578-32.49-7.762-49.494c0.813-16.935,4.981-33.181,12.391-48.286c7.73-15.758,18.662-29.53,32.486-40.929
c20.937-17.255,46.923-26.375,75.147-26.375c35.163,0,69.718,14.388,94.803,39.474l28.48,28.48
c6.564,6.563,15.466,10.251,24.749,10.251s18.185-3.688,24.749-10.251l28.479-28.479
C477.901,190.111,512.422,175.685,547.459,175.685 M547.459,140.685c-43.303,0-86.948,17.319-119.46,49.831l-28.479,28.48
l-28.48-28.48c-32.379-32.379-76.135-49.725-119.551-49.725c-34.675,0-69.131,11.063-97.407,34.365
c-72.96,60.16-76.8,168.64-11.521,233.92l245.439,245.44c3.2,3.199,7.28,4.8,11.36,4.8s8.16-1.601,11.359-4.8l245.44-245.44
c65.6-65.28,61.76-173.44-11.2-233.92C616.633,151.811,582.154,140.685,547.459,140.685L547.459,140.685z"/>
</g>
</svg>
</a></li>
</ul>
</div>
</div>
</div><!-- blocks -->
<div class="bannerSpanSection__sideBarBlock rounded-2 p-2">
<div class="table-responsive">
<table class="table table-dark table-striped table-borderless m-0 p-0">
<tr>
<td>Image type</td>
<td class="text-white">
<?php echo wp_check_filetype($imgURL)['ext']; ?>
</td>
</tr>
<tr>
<td>Image size</td>
<td><?php
$imagePath = get_attached_file(get_post_thumbnail_id());
$fileSize = filesize($imagePath);
$formattedSize = size_format($fileSize);
echo $formattedSize;
?></td>
</tr>
<tr>
<td>Resolution</td>
<td>
<?php echo getimagesize($imgURL)[0] . " x " . getimagesize($imgURL)[1]; ?>
</td>
</tr>
<tr>
<td>Uploaded on</td>
<td><?php echo get_the_date(); ?></td>
</tr>
<tr>
<td>Total views</td>
<td><?php echo gt_get_post_view(); ?></td>
</tr>
<tr>
<td>Total downloads</td>
<td id="download_counts">
<?php
$downloads = get_post_meta($post->ID, 'downloads', true);
if ($downloads == '') {
$downloads = 0;
add_post_meta($post->ID, 'downloads', $downloads);
}
echo $downloads;
?>
</td>
</tr>
<tr>
<td>Total likes</td>
<td id="download_likes">
<?php
$likes = get_post_meta($post->ID, 'likes', true);
if ($likes == '') {
$likes = 0;
add_post_meta($post->ID, 'likes', $likes);
}
echo $likes;
?>
</td>
</tr>
</table>
</div>
</div><!--- block 02 -->
</div><!-- col -->
<!-- related posts start -->
<?php
// Get the categories for the current post
$categories = get_the_category( get_the_ID() );
// Get an array of category IDs
$category_ids = array();
foreach ( $categories as $category ) {
$category_ids[] = $category->term_id;
}
// Get the tags for the current post
$tags = wp_get_post_tags( get_the_ID() );
// Get an array of tag IDs
$tag_ids = array();
foreach ( $tags as $tag ) {
$tag_ids[] = $tag->term_id;
}
// Query for related posts based on the categories and tags
$related_posts = get_posts( array(
'category__in' => $category_ids,
'tag__in' => $tag_ids,
'post__not_in' => array( get_the_ID() ),
'posts_per_page' => 12 // Change this number to set the number of related posts to display
) );
// If there are related posts, display them
if ( $related_posts ) :
?>
<div class="container"> <!-- container start -->
<div class="row overflow-hidden"> <!-- row start -->
<?php foreach ( $related_posts as $post ) : setup_postdata( $post ); ?>
<div class="col-xs-6 col-sm-6 col-md-6 col-lg-4 col-xl-3">
<a href="<?php the_permalink(); ?>">
<div class="title-box mx-auto mb-0">
<h1 class="title-color"><?php the_title(); ?></h1>
<?php
if( has_post_thumbnail() ):
the_post_thumbnail('homepage-thumbnail', array('class' => 'img-fluid'));
else:
?>
<img class="img-fluid" src="<?php echo get_template_directory_uri() . "/images/bg.jpg"; ?>">
<?php endif; ?>
<?php
$video_type = get_field('post_badge');
if($video_type!='select_type'):
?>
<div class="post-badge"><?php echo get_field('post_badge'); ?></div>
<?php endif; ?>
</div></a>
</div>
<?php endforeach; wp_reset_postdata(); ?>
</div>
</div>
<?php endif; ?>
<!-- related posts end -->
<?php
}
}
?>
</div> <!-- row -->
</div> <!-- span section -->
</div><!-- container -->
<?php get_footer(); ?>