Tag Info

New answers tagged

1

The issue is with this line: wp_localize_script( 'ajaxHandle', 'myAjax', array( 'ajaxurl' => admin_url( 'admin_ajax.php' ) ) ); It should be admin-ajax.php instead of admin_ajax.php.


-3

Change your code like this In function.php file add_action( 'init', 'so_enqueue_scripts' ); function so_enqueue_scripts(){ wp_register_script( 'ajaxHandle', get_template_directory_uri() . '/myscript.js', array('jQuery') ); wp_enqueue_script( 'ajaxHandle' ); wp_localize_script( 'ajaxHandle', 'myAjax', array( 'ajaxurl' => admin_url( ...


0

Another thing to consider is that wp nonce system uses both the current user id, and the sessiontoken (wordpress_logged_in_... cookie). If you look at wp_verify_nonce function source you'll see it compares the nonce with hash of ( current and last 12-hr period + '|' + action + '|' + currentuser-id + '|' + sessiontoken ) Any change of any of those variables ...


0

Added this code to updated the selected field by identifying the appropriate value in the taxonomy column: jQuery(document).ready(function($) { // Create a copy of the WP inline edit post function var $wp_inline_edit = inlineEditPost.edit; // Overwrite the function with our own code inlineEditPost.edit = function( id ) { // Call the original ...


0

I was able to keep the $postCount variable counting by starting a php session in my functions.php file function init_session() { session_start(); } add_action( 'init', 'init_session', 1 ); ...and setting up my loop like so: [...] <body> <div class="posts"> <?php $postCount = 0; if ( is_paged() ) : ...


1

WP_Query has a $post_count variable. http://codex.wordpress.org/Class_Reference/WP_Query#Properties Just pass that with the script using wp_localize_script


0

I have found the culprit: I was using the recommended way to do ajax in wordpress, using admin-ajax.php. Turns out it is best used for wp-admin related actions, not so much for frontend use cases. To bypass this, i created my own ajax handling file, mimicking the code found in admin-ajax.php. IF you need it, you can find it as a Gist.


-1

Have a look at this article by Michael Martin. I wanted to implement an "infinite scroll" on my site and he explained exactly what to do and how to do it. Maybe it will help you, who knows... It can be changed to load pages instead from a function.


0

I hadn't run your code, but my educated guess is that the fault in your code flow is that nonces are user specific. While anonymous nonce is possible, it is useless for its purpose because it would be same for all anonymous users. So there is likely mismatch somewhere and you are trying to use nonce of specific user, while being anonymous.


0

The action should be part of the data object: var formdata = new FormData(); formdata.append('name', 'This is Name'); formdata.append('action', 'plugin_save'); $.ajax({ url: 'admin-ajax.php', type: 'POST', data: formdata, contentType:false, processData:false, success: success, error: error });


0

You can set the amount of posts to display in the admin panel under 'Settings > Reading > Blog pages show at most .. posts'. If you want to style this afterwards, more information here: http://codex.wordpress.org/Pagination Or a useful plugin: https://wordpress.org/plugins/wp-paginate/


1

Each time you're making an ajax call, $_TEST = 0; is being evaluated again. You use the options API to manipulate your variable. function get_global_val() { $count = get_option( 'mycount' ); $count++; //or whatever you want to do with it update_option( 'mycount', $count ); die("New value is $count"); }


2

Previous Question That answer I've linked to shows the steps you'll need to take. It probably didn't come up in your searches as you weren't using the right terms. As you're a front-end dev, this is how I'd do it based on that persons advice. Don't load anything in the template. Just have an empty ul with an id you can target, and a button to use for the ...


0

For those who would know : $upload_dir = wp_upload_dir(); $image_data = file_get_contents($image_url); $filename = basename($image_url); if(wp_mkdir_p($upload_dir['path'])) $file = $upload_dir['path'] . '/' . $filename; else $file = $upload_dir['basedir'] . '/' . $filename; file_put_contents($file, $image_data); $wp_filetype = ...


0

I had the same problem. Here is the solution: jQuery(document).ajaxSuccess(function() { jQuery('.tippy').tippy({ position: "link", offsetx: 0, offsety: 10, closetext: "X", hidedelay: 700, showdelay: 100, calcpos: "parent", showspeed: 200, hidespeed: 200, target: "_blank", showtitle: true, hoverpopup: true, draggable: true, dragheader: true, multitip: ...


2

As you guess that's what happening(at least I think). You should separate your ajax logic from your "first load" logic. You can make a function ie my_get_posts that will be called inside archive-work.php and then inside ajax_filter_get_posts you can call the my_get_posts() function. archive-work.php <div class="work-results"> ...


1

I think that your problem is ajaxurl is not available for your script. Try to defined that varibale before your js code is loaded. The best way is using wp_localize_script: The PHP: add_action( 'wp_enqueue_scripts', 'cyb_enqueue_scripts' ); function cyb_enqueue_scripts() { //Change the key and url with yours wp_register_script('my-js', ...



Top 50 recent answers are included