Using AJAX to return search form results

There are two issues in your code You need to add script in wp_enqueue_scripts hooks like this – add_action(‘wp_enqueue_scripts’, ‘my_custom_js_script’); function my_custom_js_script() { wp_register_script( ‘ajax-productSearch’, get_template_directory_uri() .’/js/ajax-product-search.js’, array( ‘jquery’) ); wp_enqueue_script( ‘ajax-productSearch’ ); wp_localize_script( ‘ajax-productSearch’,’the_ajax_productSearch’, array(‘ajaxurl_productSearch’ => admin_url(‘admin-ajax.php’))); } The second issue is that, you need to add action argument in your jQuery.ajax data. If … Read more

Show only one post for each author ( Page loads too slow )

Edit: I just tested and it works perfectly. You’ll also want to remove pagination from the author template. I haven’t tested it, but have you tried pre_get_posts? function author_filter($query) { if ( !is_admin() && $query->is_main_query() ) { if ($query->is_author()) { $query->set( ‘posts_per_page’, 1 ); } } } add_action(‘pre_get_posts’,’author_filter’);

List taxonomy terms plus their latest post ordered by post date

Right now you are performing the query by term, and displaying results instantly. What you need is to gather the results of each query, sort them and then display separately. Make sure to read code comments. /* $custom_terms = get_terms(‘columna’); – this approach is depreciated */ $custom_terms = get_terms( array( ‘taxonomy’ => ‘columna’ ) ); … Read more

Set default option in dropdown of WP_Query?

(Revised answer) If I understand it properly, try these: Define $the_post for each “property”: <?php $the_post = get_post(); ?> <div class=”property-details”> <h2><?php the_title(); ?></h2> … </div> Then change the drop-down code to: <select name=”propname”> <?php $found = wp_list_filter( $the_query->posts, [ ‘ID’ => $the_post->ID ] ); if ( empty( $found ) ) : ?> <option selected><?php … Read more

Result of Custom WP_Query appears on 404 Page (but result are found!)

I found out its because I used a Input with name=”name” which caused this issue. I believe the name ‘name’ is a keyword in wordpress/php. I replaced the ‘name’ to ‘personname’ then it works as charm. … <input name=”personname” type=”text” value=”” /> … $_POST[‘gsdname’] // multiple time in my code … Best regards Floh

Get only 1 Most Recently Modified Child Post from Parent

I think maybe you don’t need Wp_Query. I believe you can just do $episodes_for_front_page = array(); //get the two dramas $dramas = get_posts(array(‘post_type’ => ‘drama’)); foreach ($dramas as $drama){ //get all the episodes belonging to that drama, sorted by most recent update $episodes = get_posts( array( ‘post_type’ => ‘episode’, ‘post_parent’ => $drama->ID, ‘orderby’ => ‘post_modified’, … Read more