Issue with Custom Content Loop in Astra Pro Theme
-
Good morning,
I am currently in the process of developing an Ajax Post Filter for a client, with the objective of dynamically displaying results via Ajax. This involves utilizing a dropdown category and three keyword dropdowns for filtering. However, I have encountered an issue as the client is utilizing Astra Pro and wishes to have the results presented in a three-column grid layout, a feature exclusive to Astra Pro.
Upon consulting the documentation, I came across the following code snippet: [Link to the documentation: https://wpastra.com/docs/restrict-search-results-post/]
Nevertheless, the results I am currently obtaining are being displayed in a vertical, one-after-the-other format, rather than the desired three-column grid layout. How can I go about achieving the layout specified in Astra Pro?
add_action('wp_ajax_nopriv_filter_results', 'filter_results'); add_action('wp_ajax_filter_results', 'filter_results'); function filter_results() { // Retrieve data from POST $category = $_POST['category']; $tags = json_decode(stripslashes($_POST['tags'])); $args = array( 'category_name' => $category, 'tag_slug__and' => $tags, 'posts_per_page' => 10 ); $query = new WP_Query($args); // Temporarily replace the main query global $wp_query; $original_query = $wp_query; $wp_query = $query; // Use the modified Astra's loop structure astra_redo_loop_markup(); $wp_query = $original_query; wp_reset_postdata(); wp_die(); }
function astra_redo_loop_markup() { global $post; ?> <main id="main" class="site-main" role="main"> <?php if ( have_posts() ) : ?> <?php do_action( 'astra_template_parts_content_top' ); ?> <?php while ( have_posts() ) : the_post(); if ( is_search() && ( 'page' == $post->post_type ) ) { continue; } do_action( 'astra_template_parts_content' ); endwhile; else : echo 'No results found.'; endif; ?> </main><!-- #main --> <?php }
- The topic ‘Issue with Custom Content Loop in Astra Pro Theme’ is closed to new replies.