Problem with multisite?

This topic contains 14 replies, has 2 voices, and was last updated by

 
Keymaster
7 years, 10 months ago.

Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #1467

    Participant

    Hello.

    I installed Ajax Search Pro in my multisite installation and i am facing this problem: No matter how i activate the plugin (network activation or per site activation), i do not get results for the current blog. I only get results if i manually add blogs to the plugin’s multisite configuration tab, but since i do not want to see any other site’s results in my current site, this does not work for me.

    (Maybe) important notice: When i first installed the plugin, i had the public attribute of all the sites deactivated, because i do not want them to be crawled by bots yet. I have tried deleting the plugin, and reinstalling it while having the public attribute enabled, but the behavior still remains: if no blog is selected in multisite settings of the plugin, no results are returned. ]

    I have not included the site credentials, because i want to be in direct contact with the person who might need access, as the site is live an people are working with it.

    Thanks!

    #1468

    Hi!

    Can you see the current site in the blog list? If so, then try to select it, that might solve this issue.

    Best,
    Ernest Marcinko

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


    #1469

    Participant

    I can see all the sites that have the public attribute enabled. However, if i select one of them, what about the other sites’ results? I want each site to show its own results.

    Basically, the problem is that “If you not choose any site, then the currently active blog will be used!” doesn’t seem to be working.

    #1471

    We might missunderstand each other. What I udnerstand is, that you want the search on each (or some) of your sites, but every one of them should only show the results from the site that they are placed on.

    Lets say you have 3 sites named: 1, 2, 3. If you want a search on site 1, you need to log in to the site 1 administrator panel and select blog 1 for that search. Then log in to site 2, then select blog 2 for that search, etc… The search field on site 1 will only search site 1 then, the search field on site 2 will only search site 2 then..
    In other words, each site must have an own search instance configured.
    This sounds like a lot of work I know, but there is no other way to create one engine for all the sites (the reasons are mainly security issues).

    I know it’s written on the admin panel, that if no sites are selected, then the current one will be used, but in some rare cases it’s not working for some reason, and I could’t figure out it yet why, and the current blog must be selected.

    Best,
    Ernest Marcinko

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


    #1472

    Participant

    That would mean that i cannot have one search form for all sites, and thus cannot insert it in a template file, because each site will have a different form id, correct?

    #1473

    It depends on various things, but the id is not really predictable.

    If you use only one search for each blog and the same template for all the sites, then editing the search shortcode is most likely the best solution for you.

    Open up the plugins/ajax-search-pro/includes/shortcodes.php and go to line 88:

    $search = $wpdb->get_results("SELECT * FROM ".$_prefix."ajaxsearchpro WHERE id=".$id, ARRAY_A);

    and change this line to:

    $search = $wpdb->get_results("SELECT * FROM ".$_prefix."ajaxsearchpro", ARRAY_A);

    plus add this line after line 99:

    $id = $search[0]['id'];

    This change in the shortcode will generally ignore the search id and selects the first one found on each sub-site. Now you can use the same template for each site with any search shortcode, like:

    <?php echo do_shortcode('[wpdreams_ajaxsearchpro_results id=0 element="div"]'); ?>

    because the id doesn’t matter anymore.

    Best,
    Ernest Marcinko

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


    #1474

    Participant

    Well, that was a smart workaround. Thanks a lot! (i think it would be great if the original functionality would also work – so as to avoid workarounds)

    #1475

    Participant

    I must be doing it wrong.

    Here is the relevant code from shortcodes.php:
    <pre class=”lang:php decode:true ” >else {
    global $wpdb;
    if (isset($wpdb->base_prefix)) {
    $_prefix = $wpdb->base_prefix;
    } else {
    $_prefix = $wpdb->prefix;
    }
    $search = $wpdb->get_results(“SELECT * FROM “.$_prefix.”ajaxsearchpro”, ARRAY_A);
    if (!isset($search[0])) {
    echo “This search form does not exist!”;
    $return = ob_get_clean();
    return $return;
    }
    if (isset($search[0][‘id’]) && isset($wpdreams_ajaxsearchpros[$search[0][‘id’]])) {
    echo “This search form is already on the page! You cannot use the same form twice on one page!”;
    $return = ob_get_clean();
    return $return;
    }
    $wpdreams_ajaxsearchpros[$search[0][‘id’]] = 1;

    $id = $search[0][‘id’];

    $search[0][‘data’] = json_decode($search[0][‘data’], true);
    $style = $search[0][‘data’];
    }

    And here is my shortcode:
    <pre class=”lang:default decode:true ” ><?php echo do_shortcode(‘[wpdreams_ajaxsearchpro_results id=0 element="div"]‘); ?>

    And here are my forms:
    http://prntscr.com/32qha1
    http://prntscr.com/32qhbj

    And here is the problem:
    http://prntscr.com/32qhdz

    The shortcode does not produce any output.

    Any ideas?

    • This reply was modified 7 years, 10 months ago by  Byron Dokimakis. Reason: tried to fix code tags (?)
    #1477

    Oh, I pasted the wrong shortcode.

    Try with this one:

    <?php echo do_shortcode('[wpdreams_ajaxsearchpro id=0]'); ?>
    Best,
    Ernest Marcinko

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


    #1478

    Participant

    Yeap, that was the reason no html was produced. However, we must be bumping on to more than a syntax problem this time.

    I have created 2 search forms, each one with a different blog assigned in multisite settings. http://prntscr.com/32qi8p

    However, the shortcode is using the first form i created, regardless of the site i am currently using. Is it normal that i can see all forms from all sites’ plugin settings?

    #1479

    Nope, it should be the other way around. I guess they must have changed something in the wordpress core with the latest minor upgrade. On my test server it shows differently.

    I guess then my first solution won’t work in this case 🙁 You should revert back the changes you made on the shortcodes.php file.

    Do you know the blog ids of your sites? If so, then you can still use the same template for each site, and create an if statement to display the corresponding search like this:

    <?php 
      $_blog_id = get_current_blog_id();
      if ($_blog_id=1) {
         //if the blog id is 1, show the search with id 1
         echo do_shortcode('[wpdreams_ajaxsearchpro id=1]');
      } else if($_blog_id=2) {
         //if the blog id is 2, show the search with id 2
         echo do_shortcode('[wpdreams_ajaxsearchpro id=2]');
      } else if($_blog_id=3) {
         //if the blog id is 3, show the search with id 3
         echo do_shortcode('[wpdreams_ajaxsearchpro id=3]');
      } 
      /* Else if statements for each blog id */
    ?>

    After inserting this you can add as many else if statements as you want, just change the numbers to the corresponding blog id and to the corresponding search id.

    Best,
    Ernest Marcinko

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


    #1480

    Participant

    I was trying to avoid that solution, it’s too brute force for me 😛

    Could you point me to the point where the current blog should be selected (if no blog is selected in multisite settings), so i can troubleshoot it a bit, and maybe make the original functionality work?

    Thanks for your time!

    #1481

    Of course, why didn’t I think of that.

    Actuall, maybe this will work. Open the plugins/ajax-search-pro/search.php file. That’s a controller type of file, it initiates the search actions.
    Line 138 should be empty, put this thing there:

    $search['data']['selected-blogs'] = array(get_current_blog_id());

    Lines 139-170 do the hard work. The foreach parses through the $search[‘data’][‘selected-blogs’] variable (array of selected blog ids), which by default shouldn’t be empty. By pasting this code it puts the current blog id there, and that’s it. I’m 99% sure, that this will finally solve the issue.

    Best,
    Ernest Marcinko

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


    #1483

    Participant

    Neat. Problem solved. Did i thank you for the fast response? 🙂

    #1484

    Yes sir 🙂

    Best,
    Ernest Marcinko

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


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

You must be logged in to reply to this topic.