problem with WordPress ajax

In general, when a ajax call usgin admin-ajax.php returns zero it means that the action is not set in the request data, or that the action callback is not found. In your case, it seems that the action callback is not found. When performing ajax call in the frontend, you need to use the action … Read more

Create onClick Event to Re-load a Widget

I think you something like this. HTML Add this in widget <a href=”https://wordpress.stackexchange.com/questions/254474/javascript:void(0)” id=”add_my_fav”>Add To Favourite<span id=”favCount”></span></a> Ajax Add this in template <?php $nonce = wp_create_nonce(‘addToFav’); ?> <script> jQuery(document).read(function(){ jQuery.ajax({ url: ‘http://example.com/wp-admin/admin-ajax.php’, data: {action:”add_to_favourite”, secret:”<?php echo $nonce; ?>”}, method: ‘POST’, success: function(res){ jQuery(‘#favCount’).html(res); } }) }) </script> PHP Add this in functions.php function addToFavourite(){ if(isset($_POST[‘secret’]) … Read more

Simple ajax call not working in wordpress plugin

You have to put the name of your wp ajax action in your data when you do the ajax call. I assume the ajax url is correct. jQuery( document ).ready(function(){ //alert(“Jquery Loaded”); jQuery(“#pub_search”).click(function(){ alert(“You clicked”); event.preventDefault(); var term= $(“#sterm”).val(); console.log(‘your term send: ‘+term); var data = {‘nwterm’: term, ‘action’: ‘litsearch’} $.get(litsearch.ajaxurl, data, function(data){ $(“#container”).html(data.response); }); … Read more

Ajax not working es expected (Returns 0)

Please try this: Add the following in your theme’s functions.php add_action( ‘init’, ‘tnc_aj_scripts’ ); function tnc_aj_scripts() { wp_register_script( “ajax_anmeldung_script”, get_template_directory_uri(). ‘/my-ajax.js’, array(‘jquery’), ‘1.0’, true); wp_localize_script( ‘ajax_anmeldung_script’, ‘mYAjax’, array( ‘ajaxurl’ => admin_url( ‘admin-ajax.php’ ))); wp_enqueue_script( ‘jquery’ ); wp_enqueue_script( ‘ajax_anmeldung_script’ ); } add_action(“wp_ajax_ajax_anmeldung”, “ajax_anmeldung”); add_action(“wp_ajax_nopriv_ajax_anmeldung”, “ajax_anmeldung”); function ajax_anmeldung() { $result[‘one’] = ‘Hey’; $result = json_encode($result); echo $result; … Read more

register ajax calls hook

Any action that fires before the AJAX call is made will work. Generally speaking, init is good choice. You mention that the ajax call is made from a “front-end form”. If that form is available to end-users who are not logged in, then you need to use: add_action (‘wp_ajax_nopriv_my_plugin_etc’, ‘my_plugin_etc’) ; See wp_ajax_nopriv_{$_REQUEST[‘action’]}. Edit Must … Read more

My ajax code not returning ajax value

In above case your ajax request is not reaching your php function, thus it founds nothing. Update your jquery function with this function jqueryfunction(id) { var value = jQuery(this).val(); if (value.length > 3) { jQuery.ajax({ url: ajaxurl, type: ‘POST’, data: { action: ‘mycustomfunction’, value: value, }, success: function (data) { console.log(data); } }); } else … Read more

When to use action hooks and plugins

First of all, see this WordPress Codex page: AJAX in Plugins You don’t technically need to write a plugin to do what you want to do, but it is good practise to do so, especially for the kind of functionality you are building. (Building a database table, handling form data, submitting with AJAX, etc.) Check … Read more

Get wp_title wp ajax

YOAST’s SEO Title is stored within a meta_key. Try this- $taxonomy = get_queried_object()->taxonomy; $term_id = get_queried_object()->term_id; $meta = get_option( ‘wpseo_taxonomy_meta’ ); $title = $meta[$taxonomy][$term_id][‘wpseo_title’]; Or this- $titles = get_option( ‘wpseo_titles’ );