The server-side code looks to be OK (at a glance) but you are not calling the correct server-side code from your JavaScript.
Have a look at this: http://wp.smashingmagazine.com/2011/10/18/how-to-use-ajax-in-wordpress/. You need to have an Ajax call to admin-ajax.php?action=<your action>
Related Posts:
- Add options to featured image
- Change meta tags programatically
- Use a function to update post meta based on other post meta
- update_post_meta for custom field not working upon form submission
- Assign category using custom field?
- Convert User ID’s to User Names in a single.php file
- Can’t check if a post has thumbnail adding filter to get_post_metadata()
- Move Post to different category if post_meta field is 0 or is 2 days old?
- What WordPress function to use to get meta value by using meta keys?
- Default Custom Field Value Automatically Update
- Function to update post_meta based on existing post_meta
- Exclude from the query posts with meta_key and meta_value
- Prevent custom field from being updated after first publish
- Get array of metakey in all posts
- User function to return multiple get_post_meta()
- What are the meta fields for an attachment?
- How to avoid saving empty data to sql while using add_meta_box
- How to change text color depending on the number value (Using javascript)
- How to add custom metakey to shop_order page’s searching function?
- Update wp_postmeta table based on 2 keys
- blank page with wp_get_attachment
- Reference multiple style sheets, clearing styles for permalink page, custom fields for css
- How To Display Author Popup on Entry Meta (Genesis Framework)?
- Creating a “Related Meta” type field?
- Remove post from latest posts after a month only with certain tag
- save_post doesn’t correctly process function call with php class
- Return ACF Field value function
- update_post_meta not working in function
- How To Get WordPress Categories Last Update Date?
- How to add a meta information to the URL?
- Automatically add custom fields (post_meta) to all published posts, hourly, via wp_cron?
- update_post_meta after form is submited
- Add custom fields after post/page title
- Display post_meta-by_key on product catalogue
- How to save custom made object in an array in a post meta field
- Adding and updating repeating custom field meta data
- Solution to render Shortcodes in Admin Editor
- How to run a function every 5 minutes?
- Define page template in wp_insert_post
- Child theme functions.php do I use php open and close tags?
- Modify Admin Bar Link
- How to override admin-bar style
- WP 4.4. responsive loads normal image after loading the responsive image
- How can I tell if I’m on a login page? [duplicate]
- Get Category and Excerpt From wp_get_recent_posts
- Two different menus for two different locations?
- Error after editing functions.php
- How do I properly register bootstrap JavaScript into WordPress functions.php?
- Most efficient way to get custom database records from 20 buttons and 20 tables?
- Manipulate Output of wp_list_something: select menu instead of li’s
- how to fix Warning: Use of undefined constant _ – assumed ‘_’ (this will throw an Error in a future version of PHP)
- restore_current_blog required after switch_to_blog, if I use that in a function?
- Empty Date Returned on my function
- Woocommerce Attributes pulling in wrong data
- How to get the post_name when in preview?
- “is_new_day()” alternative for years?
- How to hide a plugin metabox for non admins when a user adds a new post
- Getting Featured Image Caption to Only Show if Populated
- How can I change a function in a parent theme via a child themes functions.php
- How can I make a widget shortcode to control all the widgets?
- admin-ajax.php + load-scripts.php hanging for minutes
- Unique sequential reservation code
- Show image exactly defined to a width
- Modify post filter to set custom number of posts per page and exclude child posts
- Remove “Published On” inside wp-admin
- Why does get_template_directory_uri() not include “www”, only for enqueued stylesheets?
- Getting commenter meta
- How can i unload effect.min.js file?
- Native gallery custom html output
- Auto scroll to id on page load on all pages except home page. Only do this on mobile
- why is this function firing on all child menu items as well?
- Custom styles in Tiny MCE with an external CSS file
- I changed Functions.php and now I get “cannot decode raw data NSURLErrorDomain:-1015” (not blank)
- How to add schema markup to WordPress menu function
- Use add_action within template
- contact form in template with jquery,validate and ajax
- Changing the header image using WPML
- current_page_item is missing inside wp_nav_menu
- Change default upload images size for contributors
- file.php not loaded?
- How to add if statement on WordPress shortcode output
- Why does modifying the “read more” link remove the link class?
- How Do I Unhook This Parent Theme Function?
- Woocommerce product price change
- How to create an array if ’empty’?
- i can’t use wordpress functions in ajax loaded php file
- Woocommerce – Switching Price for Category
- Help wiht adding fullcalendar.io to a WordPress page
- How to create a WordPress Customizer Button to Clear a Cache?
- Move product attributes after summary on single product page
- Javascript and Stylesheet in child page
- Problem in outputting shortcode
- Custom Nested WordPress Comments with avatar
- How to get tags and categories?
- Archive.php, and post_is_in_descendant_category
- Having problems loading Jquery in functions.php
- How can I append and prepend something to all post hyperlinks without using ::before or ::after? PHP hook solution?
- How to overwrite ‘read more” text for artmag theme
- Retrieving next_post_link() and previous_post_link() in functions.php
- Using input_attrs() Multiple Times Within One Customizer Control