• Resolved vbkun

    (@vbkun)


    More a suggestion here than a problem.
    It would be great to have some way to extend the search data types without moding.
    I think this is the only thing the plugin is missing, some filters.
    If this helps anyone searching for a solution, I did a mod like this:

    1 – Delay execution of the plugin (this seems to have had no effect in functionality), changing the execution in main plugin file from:
    new ACFBetterSearch();
    to:
    add_action('after_setup_theme', function(){ new ACFBetterSearch(); } );

    2 – Created a filter in search.php, after settings were loaded inside loadSettings():
    $this->fieldsTypes = apply_filters( 'acfbs_fieldtypes', $this->fieldsTypes);

    Would be great to get something like this in an update 🙂

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    Hi @vbkun,

    You can do it now. Try using a similar code:

    add_filter('pre_get_posts', 'updatePostTypesForSearch');
    
    function updatePostTypesForSearch($query)
    {
      if (!$query->is_search || $query->is_admin) return $query;
      $query->set('post_type', ['post', 'page']);
      return $query;
    }

    Can I help you? Could you add a review to this plugin?

    Thread Starter vbkun

    (@vbkun)

    HI @mateuszgbiorczyk
    Clean code but if you notice my opening post, I wasn’t trying to include post types to search :).
    I was adding additional ACF data-types for search. (So I don’t see how using pre_get_posts can help)
    I have a bunch ACF Field types I coded myself, not to mention all the ones available in plugins repo, and didn’t found any other way to include their data type to Better Search.

    Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    Right. Forgive. These types can be set in admin panel. Can you check it?

    Thread Starter vbkun

    (@vbkun)

    Well as I mentioned… The admin panel only allows adding built-in field types, not additional field types from plugins.

    (but if I went to the trouble of finding the method which gets the settings from admin panel and created a filter there… I guess it was clear I knew the panel screen :P)

    Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    Hi @vbkun,

    I have released a new version of plugin that uses filters. You can use one of them to do what you need:

    add_filter('acfbs_options_fields', 'addCustomFieldsTypes');
    function addCustomFieldsTypes($list)
    {
      $list['custom_field'] = 'Custom field';
      return $list;
    }

    Please, let me know if everything works?

    Thread Starter vbkun

    (@vbkun)

    Working.
    Nice solution, adding the filter to change the form itself, I haven’t thought about implementing it like that!
    Thanks 😉

    Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    Hi @vbkun,

    Happy to help.

    If you want, you can add a review to my plugin. I will be grateful!

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Extending Search to plugins’ is closed to new replies.