Tag Info

New answers tagged

0

Replace the function into your functions.php file - function update_dynamic_select() { update_post_meta($_POST['aid'], $_POST['field'], $_POST['value']); echo $_POST['value']; die(); } Replace options in your HTML part - <?php $val = get_post_meta( 104, '_image_matmenys', true ); $s1 = ($val == "10x10") ? 'selected="selected"' : ''; $s2 = ...


1

For anyone that comes across this as I did via the Googlez, I was trying to load new articles onto the bottom of a single.php page (infinite scroll). I discovered that by adding an increment to the "offset" value, and then using $.post() instead of $.get(), I was able to do this. Following the code outlined above (and the subsequent change), I pulled it ...


-1

Try add do_action('admin_print_footer_scripts'); after wp_editor('','unique_id');


2

You're trying to use get_the_ID inside your callback function, but get_the_ID will only work inside the loop. You should send your post ID to your callback function explicitly instead.


1

You class method need to be static to be access without initializing the class or public in order to access from the class itself without reference &. And the variable $this->itemsClass also need to be public. So the workaround is - class Plugin { public $itemsClass; function __construct() { add_action('wp_ajax_list_items', ...


1

First, don't enqueue on the init action. Enqueue on the wp_enqueue_scripts action for the front end, or the admin_enqueue_scripts action for the back end. Second, the wp_ajax_* action will only work for logged in users. For non-logged in users, you must use the wp_ajax_nopriv_* action instead. If it needs to work for both, then you must hook both. Finally, ...


0

Try to write the 'data' and 'action' like this - action: 'send_message_to_customer' data:{'email_customer' : jQuery(this).val()} Add one more hook - add_action( 'wp_ajax_nopriv_send_message_to_customer', 'add_send_msg' );


0

The best way to go about this is with $wpdb. The query to draw out meta_value by category is: $query = $wpdb->get_results( "SELECT p.`ID`, pm.`meta_value` FROM {$wpdb->postmeta} pm LEFT JOIN {$wpdb->posts} `p` ON `p`.`ID` = pm.`post_id` LEFT JOIN {$wpdb->term_relationships} `tr` ON `p`.`ID` = `tr`.`object_id` LEFT JOIN ...


0

For anyone that may come across this issue, my problem was that I included the tw_pages_results.php file inside the template file. This will not work. So I moved my include to my function.php file and it started working.


0

Filtrify doesn't actually use AJAX to get a new data set, it simply hides all of the elements which don't match your current filter. Because you already have a page displaying all books (for example) you are already pretty well set up to use Filtrify. The only extra step that you need to take is to add the data-genre attribute to each of your books (or ...


0

I found that installing the following plugins created this error: HC Custom WP-Admin URL Peter's Login Redirect


0

Wordpress and AJAX. First, you have to register and action, and link that action to a PHP function. In that function, you can use a custom WP_Query to return the posts for each genre. You will need to use javascript to create the avascript function executed when someone clicks and option from the dropdown, that function has to make a call to the action ...


1

You are looking for get_blog_details function. $blog_details = get_blog_details( $blog_id ); Here is the official documentation.


0

You are gonna need a PHP code like this, you can add it to the functions.php, or I would recommend creating a plugin. add_action('wp_ajax_nopriv_action_name', 'ajax_function'); add_action('wp_ajax_action_name', 'ajax_function'); function ajax_function(){ $post = get_post($_POST['post_id']); $response = array("content"=> apply_filters('the_content', ...


5

There are tons of questions about using Ajax, so your question could be easily marked as duplicated but I see so BIG mistakes that I can't say to you that the question is duplicated without explaining your mistakes. The Ajax in Wordpress is handled in admin-ajax.php file, wehre you correctly sent the ajax request (see the url parameter of the Ajax call). ...


-2

Try to use complete instead of succes. Also, including wp-load isn't the best practice, what is the reason that you are including it?


0

I finally solved it, my problem was that I forget to send back the results to JS file. I did it now with: public function add_vehicle() { .... $response = json_encode( $POST ); //as sample // response output -> sent back to javascript file header( "Content-Type: application/json" ); echo $response; ...


1

Your McAdmin seems fine - the problem is likely one of two reasons: Another AJAX hook for blubb is terminating the script before McAdmin::get_vehicle You need to add the same hook for wp_ajax_nopriv_blubb - for non-logged in AJAX requests (otherwise it fails silently). If neither is the cause, you need to do a little HTTP inspecting - I use Firebug or ...


0

There are a few things going on with your functions.php file that may be the issue. You should be using wp_enqueue_scripts action to enqueue your script. The first parameter of wp_localize_script() should match the id of the file you've enqueued. You also need to add a no_priv version for your Ajax call if it needs to work for non-logged in users. Have a ...


1

If you want an example of how to do the dropdown filtering using ajax, then if you factor out your taxonomy dropdown into your "functions.php": function my_dropdown_categories( $taxonomy, $current_selected = '', $include = null ) { // Get all terms of the chosen taxonomy $terms = get_terms($taxonomy, array('orderby' => 'name')); // our ...


0

Use jQuery action on first dropdown .. this is the code from your mentioned url .. You can populate the arrays using php functions ... function dynamic1(parent,child) { var parent_array = new Array(); // This is the default value parent_array[''] = ['Please select a manufacturer']; // All other elements // parent_array['PARENT NAME'] = ...


0

The best way to know is to test yourself...but you will most likely find that the performance difference is negligible. Adding those actions don't mean that the "my_ajax_method_" will be evaluated. It is just setting up a reference...and the reference is only executed if the AJAX call comes in.


0

Are there any Console js errors? The admin-ajax.php is Wordpress's built in way of dealing with ajax so you should probably do something like this, assuming .get() would also work: $.post(ajaxurl, data, function(response) { alert('Got this from the server: ' + response); }); http://codex.wordpress.org/AJAX_in_Plugins


2

Check the constant DOING_AJAX. It is always defined when someone uses the WordPress AJAX API. if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) return; if ( is_admin() ) add_action( 'admin_init', 'xcsn_redirect_from_admin' );


0

I finally figured this out. What ended up working is putting the script portion in a .js file within the theme directory, calling it using the functions.php in my child theme, and having the HTML input field and div tag in the body of the page. Hopefully this can spare others the same pain I went through.


1

figured it out... The main problem with the scripts so just wrapped them in this for each plugin: function my_enqueue_javascript() { if (is_page('page')) { //Include Javascript library wp_enqueue_script('', plugins_url( '/js/ajax.js' , __FILE__ ) , array( 'jquery' )); // including ajax script in the plugin Myajax.ajaxurl ...


1

You have to localize script by using wp_localize_script function. In the admin side ajaxurl is already available. But in front end you have to localize script to define ajaxurl. Example: wp_enqueue_script( 'custom-ajax-request', '/path/to/settings.js', array( 'jquery' ) ); wp_localize_script( 'custom-ajax-request', 'MyAjax', array( 'ajaxurl' => ...


0

Probably it's because of this: add_action( 'wp_ajax_my_action', 'my_action_callback' ); add_action( 'wp_ajax_nopriv_my_action', 'my_action_callback' ); You have to add the action for both hooks. Probably the plugin is hooked to the second hook right now.


0

It might be due to another plugin that affects your website only to logged in users. Try to disable them one by one and see if it works.


1

Ajax endpoint is known to be relatively slow, but that primarily comes from loading WordPress core. If you are seeing drastic difference between two endpoints (native Ajax vs yours custom) that both perform core load, then something is doing something that degrades Ajax endpoint on top of it. I would profile Ajax endpoint to have better idea of what is ...



Top 50 recent answers are included