• Resolved devtat

    (@devtat)


    Am I missing something obvious? I just need ALM to load the current page’s $wp_query posts… for some context, I’m applying both ‘meta_query’ and ‘tax_query’ filters to a post-type archive page via ‘pre_get_posts’ and $_POST variables.

    I’ve tried re-creating my query with ‘alm_query_args’ but it fails at getting either $_POST or $_SESSION variables for the filters according to the debug.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Darren Cooney

    (@dcooney)

    @devtat Good question.
    ALM creates its own WP_Query so you won’t be able to just pass in an existing WP_Query and expect it to work.
    You could parse the returned query args and then pass it in, but i’m not sure exactly what you’ve tried as you did not share any code.

    Thread Starter devtat

    (@devtat)

    Code is something like this in functions.php:

    
    function theme_folio_listing($args, $id){
    $args['post_type'] = 'folio';
    $tax_query = array( 'relation' => 'AND' );
    
    if( isset($_SESSION['source']) ){
     $args['meta_query'] = array(array( 'key'=>'author', 'value' => $_SESSION['source'], 'compare' => '=' ));
    }
    if( isset($_SESSION['format']) ){
      $tax_query[] = array( 'taxonomy' => 'folio_format', 'field' => 'id', 'terms' => $_SESSION['format'] , 'operator' => 'IN' );
    } else {
      $tax_query[] = array( 'taxonomy' => 'folio_format', 'field' => 'id', 'operator' => 'EXISTS' );
    }
    if( isset($_SESSION['tags']) ){
      $tax_query[] = array( 'taxonomy' => 'folio_tags', 'field' => 'id', 'terms' => $_SESSION['tags'], 'operator' => 'IN' );
    }
    $args['tax_query'] = $tax_query;
    
    return $args;
    }
    add_filter( 'alm_query_args_folio_listing', 'theme_folio_listing', 10, 2);
    add_filter( 'alm_debug', '__return_true' );
    

    Then, on the archive page:

    
    do_shortcode('[ajax_load_more id="folio_listing" css_classes="section" container_type="section" offset="" posts_per_page="10" pause="false" transition_container_classes="folio-grid"]');
    

    ALM Debug shows me that that my $_POST/$_SESSION fail to be read and fallback to ‘else’, so how can I pass variable data to ‘alm_query_args’ – is it possible? Query variables would need to change each time page is accessed/refreshed.

    Thread Starter devtat

    (@devtat)

    Adding session_start() inside the alm_query_args function seems to have finally fixed it.

    Would have been nice to be able to pass the whole $wp_query->get('tax_query') value without having to re-create it though.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Load more current wp_query??’ is closed to new replies.