WordPress custom query by archive title

I have just made this on a rush but would you please try this : <?php if( is_tag() ){ $tag = single_tag_title(”, false); }else{ $tag=”; } if( is_category() ){ $cat = single_cat_title(”, false); }else{ $cat=””; } $args = array( ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘tag’ => $tag, ‘posts_per_page’ => $ppp, ‘category_name’ => $cat, ‘offset’ … Read more

Load .php file into div using ajax

Loading a PHP file the way you try to do it is still a direct access to the file. What you should do is “run” the file during the processing of the ajax request on the server side, and send the result back to the browser. Than you insert the result into the div. Your … Read more

Retrieve Header Background Image with AJAX

It was easier than i thought. After a lot of reading and trying I’ve finally got it ! This is the answer with explications if it can help someone. 1- In functions.php localize hero.js function mytheme_header_script() { // Adding custom javascript file to handle the header image. wp_enqueue_script(‘mytheme-hero’, get_theme_file_uri() . ‘/assets/js/hero.js’, array(‘jquery’), ”, true); // … Read more

Filter posts by categories ajax is showing all the posts

In your code, I have found 2 issues: 1) In your ajax function ajax_filter_get_posts(), you have missed tax_query in your arg. Your ajax function ajax_filter_get_posts() should be as below: function ajax_filter_get_posts( $taxonomy ) { // Verify nonce if( !isset( $_POST[‘afp_nonce’] ) || !wp_verify_nonce( $_POST[‘afp_nonce’], ‘afp_nonce’ ) ) die(‘Permission denied’); $taxonomy = $_POST[‘taxonomy’]; // WP Query … Read more

Using AJAX on Contact-form the WordPress way

EDIT TL;DRYour page is refreshing because you tell the form to load a new page (the page specified under action). Longer answerThe reason the page refreshes is because your form has an action associated with it. When I viewed your page yesterday, I saw the AJAX routine complete, and then the page refreshed. Why? Because … Read more