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 8860527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:16:58+00:00 2026-06-14T15:16:58+00:00

I am building my first plugin, and I am using as a reference the

  • 0

I am building my first plugin, and I am using as a reference the following link.
http://www.sitepoint.com/create-a-voting-plugin-for-wordpress/

and I am trying to underestand the following part of the code:

function voteme_addvote()
{
    $results = '';
    global $wpdb;
    $post_ID = $_POST['postid'];
    $votemecount = get_post_meta($post_ID, '_votemecount', true) != '' ? get_post_meta($post_ID, '_votemecount', true) : '0';
    $votemecountNew = $votemecount + 1;
    update_post_meta($post_ID, '_votemecount', $votemecountNew);
    $results.='<div class="votescore" >'.$votemecountNew.'</div>';
    // Return the String
    die($results);
}

I run the code and it works, but I just dont understand the following:

  • What is “get_post_meta” doing?
  • Does it create a custom meta field, the same as add_post_meta?, if it doesnt why there is not an add_post_meta?
  • I checked the DB, and it looks like it is creating a custom meta field… so in that order what is the difference between get_post_meta and add_post_meta?

Thanks very much for helping me understand this.

  • 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-06-14T15:16:59+00:00Added an answer on June 14, 2026 at 3:16 pm

    The first time your code runs, get_post_meta returns ” so $votemecount is set to 0. The following update_post_meta creates the new meta field as documented below. Values that start with _ are not displayed (are hidden meta fields).

    The function, update_post_meta(), updates the value of an existing meta key (custom field) for the specified post.

    This may be used in place of add_post_meta() function. The first thing this function will do is make sure that $meta_key already exists on $post_id. If it does not, add_post_meta($post_id, $meta_key, $meta_value) is called instead and its result is returned.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building a WordPress plugin using PHPExcel to export reports of student attendance. So
http://blog.jeremymartin.name/2008/02/building-your-first-jquery-plugin-that.html Based on this tutorial, I created my first plugin and made some modifications.
I've been building my first Rails app and now I'm trying to deploy it,
My team is building our first significant Silverlight application, using a 3 layered architecture
I'm building my first ASP.NET MVC website, and I'm trying to figure out how
I have set up infinite scroll on a website I am building here: http://richardgordoncook.com/fg/
I am currently building my first Immediacy Plugin, and do not have access to
I am building out my first WordPress site for a client. I really want
I'm building my first ever jQuery plugin (it's just a simple experiment). Here's what
I'm building my first Caliburn WPF application, and I find myself in the following

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.