• Hey there,

    I use ACF Pro and ACF extended to create bidirectional fields.
    My issue occur in the backend.

    As an example, I’ve got two custom types Album and Group, both with a bidirectional field “band name” as a relationship field.

    With ACF Better Search deactivated, I can look for a band in ‘Album’, it searches the band normaly, even with few characters,

    When using ACF Better Search, it looks like the setup of the plugin influenced the search in the backend. I often got ‘Error Loading’ or ‘No result’.

    Is there a way to do not influence the search result in the backend ?

    Many thanks in advance !
    Kind regards,
    XD1704

Viewing 9 replies - 1 through 9 (of 9 total)
  • Hello @xd1704 & hello @mateuszgbiorczyk,

    ACF Extended dev here ?? I will try to help you to resolve this issue.

    Regarding the bidirectional settings on relationship fields, here are some info:

    • Relationship fields return an array of ID. So I’m not sure how is it supposed to alter a search function here
    • Bidirectional settings only take actions during the saving process (not loading). So search function shouldn’t be altered eihter

    May I ask you if you get a PHP or Javascript error when you get the “Error loading” message?

    Have a nice day!

    Regards.

    Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    Hi @xd1704 and @hwk-fr,

    Thank you for your message. I don’t know exactly how your plugin works, but I will try to help you.

    I base my plug on the original ACF structure. By default ACF plugin has this structure in the wp_postmeta table:

    -----------------------------------------------------------
    | meta_id | post_id | meta_key       | meta_value          |
    ------------------------------------------------------------
    | 1000    | 100     | product_title  | Lorem ipsum dolor   |
    | 1001    | 100     | _product_title | field_5d89bb00fc4a7 |

    In addition, based on the value of field _... I look in the wp_posts table for information about the field. When using Lite mode, we only take into account the wp_postmeta table.

    Below I explain how the SQL query works. Divide them into fragments accordingly.

    Searching for records in the wp_posts table:
    SELECT DISTINCT wp_l2w_posts.* FROM wp_l2w_posts

    Searching for values in the wp_postmeta table:
    INNER JOIN wp_l2w_postmeta AS a ON (a.post_id = wp_l2w_posts.ID)

    Searching for an equivalent in the wp_postmeta table (note the correct data structure in the database):
    LEFT JOIN wp_l2w_postmeta AS b ON (((b.meta_id = a.meta_id + @@auto_increment_increment)) AND ((b.meta_key LIKE CONCAT('\_', a.meta_key))))

    Searching for information about the ACF field in the wp_posts table (not used in Lite mode):
    LEFT JOIN wp_l2w_posts AS c ON ((c.post_name = b.meta_value) AND (c.post_type = 'acf-field') AND ((c.post_content LIKE '%:"text"%') OR (c.post_content LIKE '%:"textarea"%') OR (c.post_content LIKE '%:"wysiwyg"%')))

    Default part of the query:
    WHERE 1=1 AND (

    Searching for a phrase in the wp_postmeta table:
    ((b.meta_id IS NOT NULL) AND (c.ID IS NOT NULL) AND (a.meta_value LIKE '%Lorem%'))

    Searching for a phrase as WordPress does by default:
    OR ((wp_l2w_posts.post_title LIKE '%Lorem%') OR (wp_l2w_posts.post_content LIKE '%Lorem%') OR (wp_l2w_posts.post_excerpt LIKE '%Lorem%'))

    Default part of the query:
    ) AND wp_l2w_posts.post_type = 'blog' AND (wp_l2w_posts.post_status = 'publish' OR wp_l2w_posts.post_status = 'acf-disabled' OR wp_l2w_posts.post_status = 'future' OR wp_l2w_posts.post_status = 'draft' OR wp_l2w_posts.post_status = 'pending' OR wp_l2w_posts.post_status = 'private') ORDER BY wp_l2w_posts.post_title LIKE '%Lorem%' DESC, wp_l2w_posts.post_date DESC LIMIT 0, 20

    If you have a structure other than the default one in the ACF plugin, the query will not work properly.

    Can I help you somehow?

    Thread Starter xd1704

    (@xd1704)

    I was just wondering if it wouldn’t be easier if I provide you a non-admin account so you can see the issue and the error it generates ?

    I haven’t found javascript error. it shows ‘Error loading’ only few seconds and show afterwards a result or ‘no result’.

    just made some tests with a list of ID (in a bidirectional field) containing a list of band posts; one being ‘Alive and Awaken’

    from ACF Better Search:
    1/Search for whole phrases instead of each single word of phrase
    2/Search for whole words instead of fragments within longer words (slower search)

    if I check 2/ it doesn’t find the band ‘Alive and Awaken’ if I search ‘awa’, it does if I uncheck

    I hope my explanation is clear ?

    @mateuszgbiorczyk I was just wondering if your query changes could be restricted to frontend queries using something like (!is_admin) ? but it’s probably more difficult than that

    Hello,

    Thanks for the precisions @mateuszgbiorczyk, that’s some really nice logic you’ve done here ?? ACF Extended does not alter tables or data structure, so I don’t think it comes from here.

    @xd1704: Relationship fields are not supported by ACF Better Search, the field data are composed by IDs, so you probably wrote your own search engine, right?

    BTW, the “Error loading” message come from your custom search engine and not ACF Better Search, if I understand correctly? You should probably take a look inside your search engine.

    Also, you can try to disable ACF Extended + Better Search, and then only enable ACF Better Search to see if it works as intended. (You won’t loose any data when disabling ACF Extended). But I really don’t think it comes from there (I had absolutely no report of compatibility problems with ACF Better Search).

    Regards.

    Thread Starter xd1704

    (@xd1704)

    @hwk-fr I use the plugin ACF Search as is, I haven’t customize anything

    My guess is that this is coming from the relationship / Article Object search function in combination with ACF Search, not from ACF extended itself.

    Hello,

    ACF Better Search doesn’t provide the search engine for the front-end, right? So where does the “Error loading” message appear?

    Can you make a screenshot please? (you can use https://imgur.com to upload an image).

    Regards.

    Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    The plugin only modifies the SQL database query. Does not create any search interface.

    Thread Starter xd1704

    (@xd1704)

    @mateuszgbiorczyk I guess somehow it impacts the way fields are searched in the backend

    @hwk-fr when looking for a list of article in the backend

    screenshot here
    https://www.ars-goetia.com/Capture.PNG

    Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    Please read the description of the plugin carefully.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Issue with bidirectional field ACF Pro + extended’ is closed to new replies.