Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7678573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:40:43+00:00 2026-05-31T17:40:43+00:00

I’m working on a little wordpress plugin rate my whatever. This plugin works well

  • 0

I’m working on a little wordpress plugin “rate my whatever”. This plugin works well on single posts but on blog page when there is several posts the plugin is not able to see from which post id the click has been done. It always takes the page’s firt post value.

I have added post id to id and class names to solve the issue (e g : post_id$post->ID) but now I’m blocked edting the jquery file in this way.

the php code of a post vote item :

 <input type=\"hidden\" id=\"post_id$post->ID\" value=\"" . $post->ID . "\" />
    <div class=\"vote\">
<table>
    <tr><td>
    <a class=\"vote_up\" href=\"#\"></a></td>
<td>
    <a class=\"vote_down\" href=\"#\"></a></td></tr>
    <tr>
<td class=\"up_perc$post->ID\">" . get_percentage(1, $post->ID ) ."%</td>
<td class=\"down_perc$post->ID\">" . get_percentage(2, $post->ID) . "% </td>
</tr>
    </table></div>

 <div class=\"vote_succ$post->ID\"></div>

The jquery code (for vote up, vote down is pretty the same) :

jQuery(document).ready(function($) { 


        $(".vote_up").click(function(e) { 
        e.preventDefault();

        $.post('/wp-content/plugins/rate-my-whatever/rate.php', {vote_type: "1", post_id: $("#post_id1").val()}, function(data) {

            $(".vote_succ1").html(data);
            $.post('/wp-content/plugins/rate-my-whatever/rate.php', {action: "getPercentage",  vote_type: "1", post_id: $("#post_id1").val()}, function(data2) {
                $(".up_perc1").html(data2);
            });
            $.post('/wp-content/plugins/rate-my-whatever/rate.php', {action: "getPercentage", vote_type: "2", post_id: $("#post_id1").val()}, function(data3) {
                $(".down_perc1").html(data3);
            });
        });
    });

I put staticly “1” after some id and class elements to check how my problem would be solved, it works fine with Post 1 which id and value are “1”, now I need to replace the “1” at the end of #post_id, .vote_succ, .up_perc, .down_perc by dynamic code to make it work with dynamic elements generated by the php code.

Thanks for your help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T17:40:45+00:00Added an answer on May 31, 2026 at 5:40 pm

    You need to change your code so that it operates on the unit that was clicked on, not on all objects of that class in the entire page. The easiest way to do that is to put each unit in a container div like this and use only class names, no ID values:

    <div class=\"voteUnit\">
        <input type=\"hidden\" class=\"post_id\" value=\"" . $post->ID . "\" />
        <div class=\"vote\">
        <table>
            <tr>
                <td><a class=\"vote_up\" href=\"#\"></a></td>
                <td><a class=\"vote_down\" href=\"#\"></a></td>
            </tr>
            <tr>
                <td class=\"up_perc\">" . get_percentage(1, $post->ID ) ."%</td>
                <td class=\"down_perc\">" . get_percentage(2, $post->ID) . "% </td>
            </tr>
        </table>
        </div>
    
        <div class=\"vote_succ\"></div>
    </div>
    

    And, then change the code to find the relevant object in the same voting unit that was clicked on by using $(this).closest('.voteUnit').find() to find the object in the clicked-on voting unit rather than looking in the whole web page and finding objects in all voting units. .closest('.voteUnit') looks up the ancestor chain from the item clicked on until it finds a parent with the class=voteUnit. The code can then use that as the sub-tree to search for the other objects in the vote unit.

    jQuery(document).ready(function($) { 
        $(".vote_up").click(function(e) { 
            var unit$ = $(this).closest('.voteUnit');
            e.preventDefault();
    
            $.post('/wp-content/plugins/rate-my-whatever/rate.php', {vote_type: "1", post_id: unit$.find(".post_id").val()}, function(data) {
    
            unit$.find(".vote_succ").html(data);
            $.post('/wp-content/plugins/rate-my-whatever/rate.php', {action: "getPercentage",  vote_type: "1", post_id: unit$.find(".post_id").val()}, function(data2) {
                unit$.find(".up_perc").html(data2);
            });
            $.post('/wp-content/plugins/rate-my-whatever/rate.php', {action: "getPercentage", vote_type: "2", post_id: unit$.find(".post_id").val()}, function(data3) {
                unit$.find(".down_perc").html(data3);
            });
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.