Articles of ajax

Is it safe to manually sign a user in using AJAX?

I’m adding a modal login to my theme. The most direct route is to create a template and include wp_login_form(); in it. This will load the core login that can be customized a bit later, using CSS or jQuery. However it requires the page to reload to verify the credentials. My thought was to send […]

Why Does WordPress not output admin-ajax.php path by default?

It’s not uncommon for WordPress sites to have 10+ instances of the admin-ajax.php path outputted to the front-end for use by plugins and themes. Does anyone know if there is a reason WordPress core hasn’t added this as a default? It seems like it would save a ton of duplication.

How to use wp_localize_script in a WordPress page other than functions.php?

I have a contact form in a WordPress page like this: $( ‘#contact_form’ ).bootstrapValidator({ fields: { // … }, submitHandler: function( formInstance ) { $.post( “../send-message”, $(“#contact_form”).serialize(), function( result ) { alert( pw_script_vars.State ); }); } }); When the form is submitted using the Ajax request it goes to another WordPress page titled /send-message that […]

Shortcodes not resolved in AJAX call response

I have a simple function, which returns the content of a page with the given pageID: function get_page_content(){ $id = $_REQUEST[‘id’]; $page_data = get_page($id); echo apply_filters(‘the_content’, $page_data->post_content); //echo do_shortcode($page_data -> post_content); wp_die(); } add_action( ‘wp_ajax_nopriv_get_page_content’, ‘get_page_content’ ); add_action( ‘wp_ajax_get_page_content’, ‘get_page_content’ ); But after an Update of WP and some Plugins the returned content still containes […]

Load more AJAX on WP Query

I am trying to get an AJAX WP Query loop to output 2 posts then use a ‘Load more’ button to load the next page of results. What is the best method to approach as not currently working? JS var ajaxRequest=function(){ var filter = $(‘#filter’); var page = 1; // What page we are on. […]

doing an ajax request always outputs 0

I’m trying to do an ajax request from my themes header.php file. I’ve read that I have to use the admin-ajax.php file to achieve this. So I looked for examples and found this one. My code in the header.php file looks like this: <script> $(document).ready(function(){ $(‘.test a’).click(function(){ var className = $(this).attr(‘class’); $.ajax({ url: “<?php echo […]

Create unique page without header.php for json feed

I have two WordPress sites on separate domains. I need to expose the latest posts within a category via a json feed on one site that I have to use for the other site. I’ll need to hit a “hidden” url, ex: /themes/mytheme/json_api.php?cat=news to get the json response. I’d like this json feed to be […]

php ajax problem – weird 301 responses!

hey guys, I really really need your help. I have just no idea why that happens. I’m trying to load a wordpress page with the jquery $ajax method. However my browser is crashing all the time when I try to load this page. I’ve build a kind of ajax search that requests a wordpress page […]

How can I use AJAX to save/update a widget form?

My custom widget’s form will have two pull-down menus: the content of the second menu is dependent on the user’s selection in the first menu (think of the way Country and State/Province works). I think the easiest implementation (though perhaps not the most user-friendly) would simply be to have the form automatically submit itself when […]

Display custom post data in sidebar w/ dropdown

I’m trying to set up a sidebar area that’ll do two things: Display a drop-down of posts in a given custom post types. Display post metadata (content and custom fields) if selected post The thing that’s getting me is two-fold: Having the selected post metadata display in the sidebar once selected via the dropdown Having […]