delete_user_meta Delete one value out of array

Thanks yo Howdy_McGee, Here is working code. // Remove favorite authors from current users DB function fav_author_remove_user(){ check_ajax_referer( ‘fav_authors_obj_ajax’, ‘security’ ); $remove_this_author = $_POST[‘clicked_author_id’]; if ( current_user_can( ‘edit_posts’ ) ){ $user_id = fav_authors_get_user_id(); $author_list = get_user_meta( $user_id, FAV_AUTHORS_META_KEY, true ); //print_r($author_list); $author_saved = array_search($remove_this_author, $author_list); if( FALSE !== $author_saved ){ // Remove $author_saved unset($author_list[$author_saved]); $author_arr … Read more

Handling an Ajax form submit

You should remove the link from the anchor tag: <a class=”button” href=”#” style=”background-color:white;color:black;”> <strong>Submit</strong> </a> Then your jQuery part should be: $(‘a.button’).click(function(event){ event.preventDefault(); //your ajax gets here: jQuery.ajax({ type:”post”, dataType:”json”, url: ajaxurl, data: {action: ‘submit_data’, info: info}, success: function(response) { alert(“Success”); } }); });

Filter WP user acf field by ajax

The problem is your action names don’t match In your frontend code: ?action=find_coach’; But in your backend code: add_action(‘wp_ajax_search_coach’, ‘searchLifeCoach’); add_action(‘wp_ajax_nopriv_search_coach’, ‘searchLifeCoach’); search_coach != find_coach, they have to match. Note that if this code used the REST API, it would have given a 404 and stated the problem in human readable language, e.g. { “code”:”rest_no_route”, … Read more

Appending anchor tag to next post

You can alter the links for next_post_link and previous_post_link with a filter. function alter_npppl_wpse_100919($link) { return preg_replace(‘/href=”https://wordpress.stackexchange.com/questions/100919/([^”]+)”https://wordpress.stackexchange.com/”,’href=”$1#something”‘,$link); } add_filter(‘next_post_link’,’alter_npppl_wpse_100919′); add_filter(‘previous_post_link’,’alter_npppl_wpse_100919′); The URL you get will be the default URL plus #content. If your site is generating /page/2/ then the final URL will be /page/2/#content. If you don’t want that trailing slash– the one before the … Read more

Data fetch and delete by ajax request

Why yo don’t you replace HTML again, when you edit or delete any record! What you can do here: Once the edit/delete query, you have to write query for fetch the data again from SQL and replace using ajax response.

Can’t seem to get wp_localize_script to work

I tested that code like this: wp_enqueue_script(‘jquery’); wp_localize_script( ‘jquery’, ‘MS_Ajax’, array( ‘ajaxurl’ => admin_url( ‘admin-ajax.php’ ), ‘nextNonce’ => wp_create_nonce( ‘myajax-next-nonce’ )) ); And it works but throws a Notice. It should be hooked to wp_enqueue_scripts like: function my_enqueue_scripts() { wp_enqueue_script(‘jquery’); wp_localize_script( ‘jquery’, ‘MS_Ajax’, array( ‘ajaxurl’ => admin_url( ‘admin-ajax.php’ ), ‘nextNonce’ => wp_create_nonce( ‘myajax-next-nonce’ )) ); … Read more