Support » Plugin: ACF: Better Search » Imports from WP All Imports aren’s searchable

  • Resolved jmaver

    (@jmaver)


    I have a bunch of products with product IDs that are ACF. Any products that were imported fail to show up in search results, any manually added afterwards succeed.

    So, I exported all the the products in my local test instance, deleted all of them, and then reimported them again. Now none are searchable.

    What can I do to fix the search for imported posts?

Viewing 8 replies - 16 through 23 (of 23 total)
  • kryonos

    (@kryonos)

    This version of the plugin seems to work perfectly

    Thread Starter jmaver

    (@jmaver)

    Trying now and timing with a few options:

    Results:
    https://www.dropbox.com/s/ehb0j6z6k2calbr/ACF%20Search%20Results.png?dl=0

    So if I don’t have ACF Better Search, I get no acf fields in results, which makes sense.

    If I don’t include the reverse query, then I don’t get imports.

    With the reverse query, all works find, although a little slower for search, except in the media library, where is is unbelievably slow.

    Is there a way to shut off ACF search for media library queries?

    Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    @jmaver, searching is very slow because you probably have a lot of items in your media library. Similar problems will occur when someone has a lot of posts of one type.

    Hi @mateuszgbiorczyk
    I installed the plugin you sent. But it does not work for me. Still the same. Do you need anything from my side?

    @guddu1315
    I suggest that you open your own thread.
    Things get hard to follow when several troubleshooting sessions interleave. Also: when you reuse someone else’s thread, you send notifications to all other people in the same thread (if they checked the box that they want notifications from the thread).
    If you feel that you’ve got the same problem that someone else has, you can give a link to the other thread, where the symptoms of someone else are described.

    FYI: @mateuszgbiorczyk

    Thread Starter jmaver

    (@jmaver)

    Ok, the slow media library got me, so I spent the time to create this (I am sure) horrible SQL statement to fix the ordering issue for the fields I care about.

    I take no responsibility for this, and it may wreck your database. I did mine on a local copy of my database and used Adminer to test.

    Here is the code:

    UPDATE wp_postmeta AS a
    INNER JOIN wp_postmeta as b USING (post_id)
    SET a.meta_key=(@temp:=a.meta_key), a.meta_key = b.meta_key, b.meta_key = @temp, a.meta_value=(@temp2:=a.meta_value), a.meta_value = b.meta_value, b.meta_value = @temp2
    WHERE a.meta_key IN ('field1', 'field2')
     AND b.meta_key = CONCAT("_",a.meta_key) AND (a.meta_id > b.meta_id);

    Steps if you want to play with it:
    1) Get a list of the fields you care about. I exported mine for one field group in ACF->Tools->export, brought it into excel, used a dataquery to extract the field names, then added the commas. You only need the fields without the “_” at the beginning.

    2) Make sure you actually have this problem, with the “_” versions of fields coming before the non-“_” versions. You can use this code to test:

    select a.post_id, a.meta_id, a.meta_key, a.meta_value, b.meta_id, b.meta_key, a.meta_value from wp_postmeta a
    INNER JOIN wp_postmeta b
    USING (post_id)
    where a.meta_key IN ('field1', 'field2')
     and b.meta_key = CONCAT("_",a.meta_key) and (a.meta_id > b.meta_id )
    order by a.meta_id ASC

    3) Get some tests in place first. Search on home page and in media library for the fields. Turn off the new “reverse” checkbox in the test version we just got.

    4) Run the update sql

    5) Run the tests again and see if they work and if they are fast.

    Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    Hi @jmaver,

    Thank you for your message. I understand your performance issues, but I have already explained to you why this is happening.

    I am not able to execute the UPDATE command on my database, let alone add this to the plugin. I hope that you understand me.

    And use the following code in your theme:

    add_filter('acfbs_search_is_available', function($status, $query)
    {
      if (isset($query->query_vars) && isset($query->query_vars['post_type'])
        && ($query->query_vars['post_type'] === 'attachment')) return false;
    
      return $status;
    }, 10, 2);

    The above code is an example that skips the search for attachment Post Type. Modify them for your needs. Thanks to this, it will be able to disable search in specific situations.

    Thread Starter jmaver

    (@jmaver)

    @mateuszgbiorczyk of course, that post wasn’t so much for you as for anyone that wants try to fix the underlying issue that WP All Imports caused with the field order.

    Your plugin change was great for me because it allowed our live site to continue to function with the bad state of the import. Thank you for the quick turnaround.

    It was just bothering me all weekend that I couldn’t fix the actual problem in the database, so I spent a bunch of time today relearning SQL enough to get rid of the issue. I expect that almost everyone else in the world will not ever look at this code, but instead will benefit from your more recent change. It would not make sense to put into your plugin. (I see I used the word “your” in my previous post, but I meant “the reader” who discovers this post later.

    That filter is also very useful. Thank you!

Viewing 8 replies - 16 through 23 (of 23 total)
  • The topic ‘Imports from WP All Imports aren’s searchable’ is closed to new replies.