Jquery wrap permalink in a data-attribute?
To set an attribute you will need to do $(this).attr(‘data-url’, call_url[“permalink”]); To update $(this).data(‘url’, call_url[“permalink”]);
To set an attribute you will need to do $(this).attr(‘data-url’, call_url[“permalink”]); To update $(this).data(‘url’, call_url[“permalink”]);
Okay, with some great examples from : https://restfulapi.net/resource-naming/ and http://www.restapitutorial.com/lessons/restfulresourcenaming.html I’m going to answer my own question. ESSENTIALLY, for my use case, I will NOT use PUT but rely on POST and DELETE to collection and singleton endpoints. Notes: I’ve omitted the wp-json/my-site-namespace/v1 prepending examples for clarity I’ve used query strings in POST requests but … Read more
As foo is a static function you don’t need to specify the object, so you can use it outside the condition to correctly load it like this : public function __construct(){ if( isset( $_GET[“page”] ) && $_GET[“page”] === ‘edit-foo’ ){ add_action( ‘admin_init’, array($this, ‘init’) ); } add_action(‘wp_ajax_foo’,array( ‘MyPlugin/Classes/MyClassWithFooFunction’, ‘foo’ ) ); } init(){ … <- … Read more
Why function called by admin-ajax executes synchronously?
I made some simple changes to your ajax function call and your ajax-js call.I hope this helps out ajax function call: $return = array(); $paged = $_POST[‘page’]; ob_start(); $args = array( ‘post_type’ => ‘book’, ‘posts_per_page’ => 3, ‘paged’ => $paged, ); $query = new WP_Query($args); while($query->have_posts() ): $query->the_post(); ?> <div class=”ajax”> <?php the_title(); ?> </div> … Read more
The wp_ajax_ is a prefix for your ajax action. your action is my_tag_count so its should be: add_action( ‘wp_ajax_my_tag_count’, ‘my_action’ ); You tried to access the wrong url in the ajax request because you set wp_localize_script( ‘custom’, ‘my_ajax_obj’, $ajax_url ); So the the request url should be my_ajax_obj its not an object its don’t have … Read more
delete post meta data in array WordPress
check_admin_referer fails on new AJAX plugin uninstall with “Are you sure you want to do this?”
to pass a variable from JavaScript to the AJAX call, you have to put the message in the data : data : {“message” : “my message”} and you retrieve it in the PHP code : function testAJAX() { $returnArray = array(); $returnArray[‘message’] = $_POST[“message”]; wp_send_json($returnArray); } you can read about the use of wp_send_json here … Read more
Yes that would be easy. You can use the get_the_permalink() function to retrieve a post’s link. Here’s how to do it: // You are storing the post data here $posts_arr[] = $post; // Add the URL to the same array element $posts_arr[][‘url’] = get_the_permalink(); You can get the index of the current post in the … Read more