Home Forums Backend Issues (wp-admin) Post Object search by ID or SKU


Post Object search by ID or SKU

  • Hello. I have a question.

    I have a “Post Object” field for products.
    But I have many of the same product names and I want to search products via SKU in my admin panel. How I can do that?

  • There isn’t any easy way to alter the search to search by custom fields.

    see explanation here

    In your case you would use an acf/fields/post_object/query filter instead of acf/fields/relationship/query

  • I saw those topics, but if to be honest I don’t understand what exactly I need to do, can you help me?

  • Going to be honest, I don’t generally do things like this, all I can do it repeat the examples.

    Basically you add an acf filter for your field

    add_filter('acf/fields/post_oject/query/name=YOUR-FIELD_NAME', 'YOUR_FUNCTION_NAME', 10, 3);
    function YOUR_FUNCTION_NAME($args, $field, $post_id) {
      // inside of this filter you add the filters described 
      // for searching post meta
      // as described here and in other places
      // this is done so that the filters will only be added for
      // this particular field in the admin
      add_filter('posts_join', 'cf_search_join');
      add_filter('posts_where', 'cf_search_where');
      add_filter('posts_distinct', 'cf_search_distinct');

    Then you add the other function to search by what you want to search by. You will need to refer to the WC documentation for what field to look at for sku.

  • Issue resolved. Thank you!

  • Just can you change the error in your code, please

    add_filter('acf/fields/post_oject/query/name=YOUR-FIELD_NAME', 'YOUR_FUNCTION_NAME', 10, 3);


    add_filter('acf/fields/post_object/query/name=YOUR-FIELD_NAME', 'YOUR_FUNCTION_NAME', 10, 3);


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

You must be logged in to reply to this topic.