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 has 8 replies, 2 voices, and was last updated 2 years, 3 months ago by
Ernest Marcinko.
-
AuthorPosts
-
February 26, 2024 at 1:12 pm #47080
pbaines
ParticipantHi 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
February 26, 2024 at 2:20 pm #47081Ernest Marcinko
KeymasterHi 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.February 26, 2024 at 6:19 pm #47089pbaines
ParticipantThanks 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>'; ?>February 26, 2024 at 6:34 pm #47091pbaines
ParticipantHi 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
February 27, 2024 at 1:53 pm #47095Ernest Marcinko
KeymasterGreat 🙂
February 27, 2024 at 3:50 pm #47098pbaines
ParticipantHi 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
February 27, 2024 at 4:15 pm #47099Ernest Marcinko
KeymasterSure 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',February 28, 2024 at 5:17 pm #47123pbaines
ParticipantMany 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
February 29, 2024 at 4:05 pm #47134Ernest Marcinko
KeymasterHi,
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 viarestore_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. -
AuthorPosts
- You must be logged in to reply to this topic.