WordPress update_comment_meta onclick not working with Ajax

I’m attempting to update_comment_meta via Ajax call in WordPress, but no data is returned and the comment_meta field is not being updated.


add_action( 'wp_enqueue_scripts', 'comment_voting_enqueue_scripts' ); function comment_voting_enqueue_scripts() {   wp_enqueue_script( 'comment_meta_voting-js', get_template_directory_uri() . '/js/ajax-vote.js', array( 'jquery' ), '0.5', false );   wp_localize_script( 'comment_meta_voting-js', 'commentMetaVoting', array(     'ajaxurl' => admin_url( 'admin-ajax.php' ),   ) ); } add_action( 'wp_ajax_nopriv_comment_meta_voting', 'comment_meta_voting' ); add_action( 'wp_ajax_comment_meta_voting', 'comment_meta_voting' );  function comment_meta_voting() {     $  comment_id = $  _POST['vote'];     $  vote_total = get_comment_meta($  comment_id , 'vote', true);     ++$  vote_total;     update_comment_meta($  comment_id , 'vote', $  vote_score );     die(); } 


(function($  ) {     'use strict';     $  (document).on('click', '.sl-button', function() {         var button = $  (this);         var cmnt_id = button.attr('data-post-id');         var security = button.attr('data-nonce');              $  .ajax({                 type: 'POST',                 url: commentMetaVoting.ajaxurl,                 data : {                     action : 'comment_meta_voting',                     post_id : cmnt_id,                     nonce : security,                 },                 success: function(response){                     console.log('tst');                 }             });          return false;     }); })(jQuery); 

and in wp_list_comments callback i add core function where i want to show the link to call:

     <a href="<?php echo admin_url( 'admin-ajax.php?action=comment_meta_voting' . '&cmnt_id=' . $  commentid . '&nonce=' . $  nonce ); ?>" class="sl-button" data-nonce="<?php echo $  commentid ; ?>" data-post-id="<?php echo $  commentid ; ?> ">click</a> 

Finally i get console.log(‘tst’); in thee console.. so i think its correct, no data is returned and the comment_meta field is not being updated..

any help?

WordPress Child Theme Issue


I have created a child theme for my blog because I have been offered some advertising and need to hard code it. In truth should have done it before – but never mind.

Anyway the child theme is working except for one thing – the background image on my post. It is a blog about a football team and I have a faded image as a background. However I can't find where I added it to replicate in the child theme. It's not in the style sheet, I've checked (which is why I posted here) – but I can't…

WordPress Child Theme Issue

How can I properly loop through an array gotten from my wordpress database and display it to my site

I am trying to display some posts information from my database on my live site. I have done the query correctly because I can view the items on the live site. But I need to take three items to display. The post title, the post content which houses the images, and the post id which links to the posts. I seem to have written it correctly but it does not do anything.

This is the code

<?php      global $  wpdb;                    $  results = $  wpdb->get_results( "SELECT * FROM $  wpdb->posts WHERE `post_type`='post' AND `post_status` = 'publish' LIMIT    20" );    foreach ($  results) {       echo "<div class="card">             <div class="img">              <img src="{post_content}" alt="">             </div>             <div class="info">                <h5>{post_title}</h5>             </div>           </div>";   }    //echo "<pre>";print_r($  results);echo"</pre>";                      ?>  

I am quite new to wordpress and PHP in general.

How do I integrate vanilla Javascript to a wordpress website?

I am new to WordPress but I have been learning to code since February. I am helping a friend add a responsive slider to her WordPress website. I created this slider using HTML, CSS and JS and it works perfectly. However, I am having problems integrating them into WordPress.

The JS code is

const prev = document.querySelector('.prev'); const next = document.querySelector('.next'); const track = document.querySelector('.track'); const carouselWidth = document.querySelector('.carousel-container').offsetWidth; let index = 0; let initialPosition = null; let moving = false; let transform = 0; next.addEventListener('click', ()=>{   index++;   prev.classList.add('show');   track.style.transform = `translateX(-$  {index * carouselWidth}px)`;   if (track.offsetWidth - (index * carouselWidth) < carouselWidth) {     next.classList.add('hide');   } });  prev.addEventListener('click', ()=>{   index--;   next.classList.remove('hide');   if (index === 0) {     prev.classList.remove('show');   }   track.style.transform = `translateX(-$  {0}px)` })    const gestureStart = (e) => {   initialPosition = e.pageX;   moving = true;   const transformMatrix = window.getComputedStyle(track).getPropertyValue('transform');   if (transformMatrix !== 'none') {     transform = parseInt(transformMatrix.split(',')[4].trim());   } }  const gestureMove = (e) => {   if (moving) {     const currentPosition = e.pageX;     const diff = currentPosition - initialPosition;     track.style.transform = `translateX($  {transform + diff}px)`;     } };  const gestureEnd = (e) => {   moving = false; }  if (window.PointerEvent) {   window.addEventListener('pointerdown', gestureStart);    window.addEventListener('pointermove', gestureMove);    window.addEventListener('pointerup', gestureEnd);   } else {   window.addEventListener('touchdown', gestureStart);    window.addEventListener('touchmove', gestureMove);    window.addEventListener('touchup', gestureEnd);        window.addEventListener('mousedown', gestureStart);    window.addEventListener('mousemove', gestureMove);    window.addEventListener('mouseup', gestureEnd);   }  

This is the code I added to the functions.php file. It adds all the CSS styles correctly.

function responsive_header(){         wp_enqueue_style( 'responsive_header_css', get_template_directory_uri() .'/css/responsiveslider.css' , array() );         wp_enqueue_script('responsive_header', get_stylesheet_directory_uri() . '/js/responsiveslider.js', array(), '',  false);          }     add_action('wp_enqueue_scripts', 'responsive_header'); 

What is weird is that if I add a hello world alert to my script it works but nothing else works. Am i doing this wrong or must I use jquery. I dont know jquery but I can learn it to implement this.

how to make my custom gallery work in wordpress

So am creating a custom theme in WordPress and looking to achieve this enter image description here

I was able to output my category but not too sure how to output the remaining information. As you can see from the image below for each category there is a recent blog post on the left and then other blog post in the same category on the right.

Below is my code please advise what am doing wrong.

<?php  global $  post;     $  args = array(        'posts_per_page' => 4,        'post_type'     => 'post',        'orderby' => 'ASC',                );                        $  query = new WP_Query($  args);             while($  query->have_posts()): $  query->the_post();             $  taxonomy = 'category';             $  term = wp_get_post_terms($  post->ID, $  taxonomy);             ?>                                                 <!-- Left Details Caption -->                                         <div class="col-xl-6 col-lg-12">                                             <div class="whats-news-single mb-40 mb-40">                                                 <div class="whates-img">                                                     <?php the_post_thumbnail('small');?>                                                 </div>                                                 <div class="whates-caption">                                                     <h4><a href="latest_news.html"><?php the_title();?></a></h4>                                                     <span>by <?php the_author();?>   -   <?php echo esc_html(get_the_date()); ?></span>                                                     <p><?php the_excerpt();?></p>                                                 </div>                                             </div>                                         </div>                                           <!-- Right single caption -->                                          <div class="col-xl-6 col-lg-12">                                             <div class="row">                                                 <!-- single -->                                                 <div class="col-xl-12 col-lg-6 col-md-6 col-sm-10">                                                     <div class="whats-right-single mb-20">                                                         <div class="whats-right-img">                                                         <?php the_post_thumbnail('small');?>                                                         </div>                                                         <div class="whats-right-cap">                                     <?php if ($  term && !is_wp_error($  term)) :?>                                         <?php foreach ($  term as $  serv_terms) :?>                                                             <span class="colorb"><?php echo $  serv_terms->name;?></span>                                         <?php endforeach; endif;?>                                                             <h4><a href="<?php the_permalink();?>"><?php the_title();?></a></h4>                                                             <p><?php echo esc_html(get_the_date()); ?></p>                                                          </div>                                                     </div>                                                 </div>                                                                                          </div>                                         </div>                          <?php endwhile; wp_reset_postdata();?> 

WordPress + Vue — Single page app giving me 404s when I use query params

I’ve got my rest api powered site working really well with Vue. Except for the issue of WordPress and urls.

Site: http://mytely.ca/

Search for a name or click on a name and the url updates. Now refresh the page. Everything still works, in that Vue will take over and do all the requests and set things up. But I’m getting a 404 on every page like that.

I don’t really know anything about this whole thing. I tried setting up a redirect plugin but that does what it says — it redirects from http://mytely.ca/&page=1&search=John%20Doe back to http://mytely.ca, which isn’t what I want.

I basically want WordPress to ignore the urls completely — just have index.php (and hence Vue) takeover everything. Basically, not 404 and just pass on through with the url.

I’m not currently using Vue Router at all in my app — just appending query strings and using popstate. I’m wondering if I actually need to be using Vue Router to handle this.

WordPress or custom coding better for this project?

I’m a LAMP developer with a ton of experience building custom-coded websites in a variety of PHP frameworks who has been tasked to develop a website for a customer who strongly prefers that I use WordPress. My WordPress knowledge is extremely limited. I have built a couple of simple sites using Envato themes that didn’t really require any custom plugin development, or meddling with source code.

This site would be different. It would be a custom fitness tracking website where users can login, view videos of exercises, and log their workouts. (Yes, I know there are a million of these out there, but this company wants their own).

Here’s an overview of my major requirements:

  • Customer accounts with secure login
  • Paid Subscriptions with multiple levels allowing access to different features
  • Videos of exercises
  • Forms to log progress (time, reps, etc.)
  • Charts and graphs to view progress
  • Leaderboard to show comparisons of members
  • Ability for future iOS/Android apps to integrate with the website/database

From my limited knowledge of WordPress, I would have to build some custom plugins for this. I don’t see anything out there that would accomplish all of these requirements. I’m also assuming that I would need a separate MySQL database to store the majority of this data.

Are these requirements able to be accomplished with WordPress in a relatively straightforward manner? How would a WordPress expert go about tackling this project?

WordPress ajax serial processing of and sending

I want to install/activate plugins via ajax.But i want to add a loading class on plugins list item which is being installing or activating. In jquery If i want to do it i need to write a lot bunch of code there.For example I have 4 plugins to install.So i have to first, send first ajax request to install first plugin then when a response comes I send second request in success block but its too time consuming. I want to know if there is any easy solution. Or in php file can i send a response back then continue installing 2nd one. Is that possible??