Hot answers tagged ajax
2
First, don't use query_posts.
Second...
I think this can be done with AJAX but is there a more simple method
and give me a clean URL?
PHP runs on the server. Items are "clicked" on the client machine. The only way to pass that "clicked" value back to PHP is via AJAX. Within a WordPress framework that mostly means using the WordPress AJAX API.
So, ...
2
Your add_action() calls for the AJAX handlers are too late.
Add these hooks earlier, the best action is probably wp_loaded:
add_action( 'wp_loaded', 'register_ajax_handlers' );
function register_ajax_handlers()
{
add_action( 'wp_ajax_jp_ajax_request', 'jp_ajax_process');
add_action( 'wp_ajax_nopriv_jp_ajax_request', 'jp_ajax_process');
}
See ...
2
Those is_page_template call will all be false. The AJAX request is an independent request to the server from the client browser. As far as that AJAX request is concernend the page you are on is admin-ajax.php. You will need to pass a parameter with the AJAX request that you can use to determine which shortcode to run. For example:
data : ( {
...
2
WordPress loads jQuery in NoConflict mode. Do not use $. Use
jQuery or one of the other solutions in the Codex.
If that Javascript is in a .js file, that is not going to work.
You cannot run PHP in a Javascript file like that, without
reconfiguring the server, and the call to get_the_ID would likely
fail anyway.
You are directly loading a .php file. That ...
2
You have a space in your function name on the action call,
add_action( 'wp_ajax_nopriv_ MyAjaxFunction', 'MyAjaxFunction' );
add_action( 'wp_ajax_ MyAjaxFunction', 'MyAjaxFunction' );
...should be,
add_action( 'wp_ajax_nopriv_MyAjaxFunction', 'MyAjaxFunction' );
add_action( 'wp_ajax_MyAjaxFunction', 'MyAjaxFunction' );
1
That's not the right way to specify data.
When you're using jQuery AJAX, you specify data as an array or an object when passing it in to the method. In your question, it seems like
'filters_get' === '?actor=x&'
Instead, you should do the following:
filters_get = {
'actor': 'x'
};
$.ajax({
url: templatePath + "getmovies.php",
type: ...
1
Please use the available API - as you have it in your question I could take down your entire site in a second. (I wrote this tutorial on Data Sanitization and Validation - the last section is particular relevant to you).
As for it not inserting the data, you should check WP_DEBUG is turned on, and also print what $wpdb->query( $sql ) responds. But in any ...
1
I don't know if there is really a right answer to this question, and I don't know what you find cumbersome about wp_localize_script, but you should be able to do it either way.
The difference is that with wp_localize_script the data is printed to the source of the page, which you wouldn't want if the data were sensitive, and wp_localize_script should ...
1
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="([^"]+)"/','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 ...
1
WordPress does not natively use Ajax submits with Settings API, so there isn't really best practice for it. I remember scbFramework having such option, but it was removed.
Essentially there is nothing inherently more insecure to such submit, you should treat form data as untrusted regardless of submit method and appropriately sanitize and validate it in PHP ...
Only top voted, non community-wiki answers of a minimum length are eligible