Accessing the index outside of the search form (e.g. for post loop)

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Accessing the index outside of the search form (e.g. for post loop)

This topic contains 8 replies, has 2 voices, and was last updated by Ernest Marcinko Ernest Marcinko 3 months, 3 weeks ago.

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #47080
    pbaines
    pbaines
    Participant

    Hi there,

    We have a multisite install and we’re currently trying to build a slider which contains posts and pages from a main site and another subsite. We have everything working in the search form, but we were wondering if we can access the index that the search form uses outside of the form.

    My theory is that this index might be able to be referenced somehow within a wp query, which would save us installing another plugin and building another multisite index for use within a slider.

    Is this possible, and if so, do you think you’d be able to point us in the right direction for use within a WP query?

    Many thanks,

    Peter

    #47081
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi Peter,

    I think there is a way to do this, I sugget using the ASP_Query class for it.
    In the arguments list you can specify the engine:
    'engine' => 'index'
    For the full list of arguments check this documentation.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #47089
    pbaines
    pbaines
    Participant

    Thanks Ernest,

    I’ve been checking out the docs, and have created a quick test, which I’ve posted below. Unfortunately, it looks like I’m still only receiving results from the current blog though, not the other blogs in the multisite. Is there anything I need to add to the args to include the multisite results? I’ve tried both the regular engine and the index engine as options.

    <?php
    
    $args = array(
      'post_type' => array('article', 'link', 'meeting', 'presentation', 'video', 'page'),
      'engine' => 'index',
      'post_primary_order' => 'post_date ASC',
    
    );
    $asp_query = new ASP_Query($args);
    echo '<ul>';
    foreach ( $asp_query->posts as $result ) {
    	// do your thing
        echo '<li><a href="' . $result->asp_guid . '">' . $result->post_title . '</a></li>';
    }
    echo '</ul>';
    
    ?>
    • This reply was modified 3 months, 4 weeks ago by pbaines .
    #47091
    pbaines
    pbaines
    Participant

    Hi Earnest,

    Sorry, me again!

    I’ve figured it out – I was missing the search ID from the ASP_Query function!

    Many thanks for your help.

    Peter

    #47095
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Great 🙂

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #47098
    pbaines
    pbaines
    Participant

    Hi Earnest,

    Sorry, one more quick question on this thread!

    I have another slider, and I need to sort it numerically by views. Each page/post should have post meta for views, with the key ‘post_views_count’ and a numerical value.

    I’ve tried using the following, but keep returning no results. Is there anything else I need to add here?

    ‘post_primary_order’ => ‘post_views_count DESC’,
    ‘post_primary_order_metatype’ => ‘numeric’,
    ‘_post_primary_order_metakey’ => ‘post_views_count’,

    Many thanks,

    Peter

    #47099
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Sure Peter!

    The custom field order is a bit tricky, I don’t think it’s documented either, but this should work:

      'post_primary_order' => 'customfp DESC',
      'post_primary_order_metatype' => 'numeric',
      '_post_primary_order_metakey' => 'post_views_count',
    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #47123
    pbaines
    pbaines
    Participant

    Many thanks Ernest.

    Last question (I promise!)

    We have 2 sliders on many pages, and it seems that having 2 ASP_Query foreach loops on one page seem to be causing some strange issues.

    For example, the template that we are calling in the second foreach loop is changing the lookup directory and giving us an error.

    It’s looking for ‘/wp-content/themes/ispn/slider/single-slider-item.php’ (The other sub-site theme) when within the previous foreach loop, the template we are including is looking for ‘/wp-content/themes/ispn-library/slider/single-slider-item.php’. It’s using the same include line, so these should be the same. Its also breaking some elementor templates below, by looking for templates within the other subsite, instead of the current site. (Screenshot attached)

    My thoughts are that perhaps this ASP_query needs to be reset somehow, before calling it again? Does that sound right?

    I think we’re nearly there!

    Thanks,

    Peter

    Attachments:
    You must be logged in to view attached files.
    #47134
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    It does not need resetting, there are no static things that should change the outcome.

    Multisites are a bit weird to handle, but can so try switching to the current site back after every ASP_Query loop, like this:

    restore_current_blog();

    I have checked the queries, but I don’t see a missing switch anywhere. This is very likely the cause though, as to search across the sites a switch_to_blog() is called, and after it’s finished the plugin reverts back to the current via restore_current_blog();

    My guess is that there is either a missing restore_current_blog(); somewhere I didn’t notice, or it does not have an effect.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


Viewing 9 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic.