Ajax Dynamic Archives not showing correct results

this is what i ended up with which works nicely. functions.php part <?php function scripts_enqueue() { if(is_page(‘archives’)) { wp_enqueue_script(‘ajax_dropdown’, get_stylesheet_directory_uri() . ‘/js/loadposts.js’,array(‘jquery’)); wp_localize_script( ‘ajax_dropdown’, ‘myajax’, array(‘custom_nonce’ => wp_create_nonce(‘nonce-ajax-dropdown’), ‘ajaxurl’ => admin_url( ‘admin-ajax.php’ ) ) ); } } add_action( ‘wp_enqueue_scripts’, ‘scripts_enqueue’ ); function wp_ajax_load_posts(){ if(!wp_verify_nonce( $_GET[‘_wpnonce’], ‘nonce-ajax-dropdown’)) die( ‘Go away!’ ); $args = array( ‘year’ => … Read more

ajax, right way to do it and make it works?

In your functions.php file you should add an action to enqueue your scripts. <?php function my_enqueue_scripts() { wp_enqueue_script( ‘load_post’, get_template_directory_uri() . ‘/js/load_post.js’, array( ‘jquery’ ), ‘1.0’, 1 ); wp_localize_script( ‘load_post’, ‘wp_ajax’, array( ‘url’ => admin_url( ‘admin-ajax.php’ ), ‘nonce’ => wp_create_nonce( ‘ajax_nonce’ ) ) ); } add_action( ‘wp_enqueue_scripts’, ‘my_enqueue_scripts’ );

Fetching more posts in WordPress via AJAX

I ended up modifying the archive.php file to serve different content when requested normally and via ajax. if ((isset($_SERVER[‘HTTP_X_REQUESTED_WITH’]) && strtolower($_SERVER[‘HTTP_X_REQUESTED_WITH’]) == ‘xmlhttprequest’)) { $response = array(); $response[‘posts’] = ”; if (have_posts()) { ob_start(); while (have_posts()) { the_post(); get_template_part(‘content’); } $response[‘posts’] .= ob_get_clean(); } else { //no posts $response[‘posts’] .= ‘nothing’; } echo json_encode($response); } … Read more

wp_handle_upload returns empty error array

Okay so Milo was on track to what the answer was. and I needed to brush up on muliple file uploads… anyway the solution for me to at least get it to upload… was this $daFile = $_FILES[‘files’]; foreach ($_FILES[‘files’] as $key => $value) { $daFile[$key] = $value[0]; } $upload = wp_handle_upload($daFile , array(‘test_form’ => … Read more

Ajax load more button in Recent posts widget

Look at WordPress’s documentation on AJAX In your theme or plugin, you’ll want to have code like: add_action(‘wp_ajax_my_load_recent’, ‘my_load_recent_posts’); add_action(‘wp_ajax_nopriv_my_load_recent’, ‘my_load_recent_posts’); function my_load_recent_posts() { $args = array( /* Arguments go here, i.e. how many posts to get */ ); query_posts($args); /* [1] */ /* Header wrap output */ if (have_posts()) : while (have_posts()) : the_post(); … Read more

Get the_content with ajax

I’m sorry but I think you have not read a good tutorial. If you are new to WordPress AJAX, I recomend you reading AJAX in WP Codex and examples plus all the examples you can find in this site.

Ajax custom search not functioning as expected

OK… this turns out to be due to a chunk of code I thought was unrelated. In an effort to keep users out of wp-admin I had added: function foobar_redirect_admin() { if( !current_user_can( ‘edit_posts’ ) ) { wp_redirect( site_url() ); exit; } } add_action( ‘admin_init’, ‘foobar_redirect_admin’ ); And that would redirect non-admin users away from … Read more