• Resolved Jason Wong

    (@eljkmw)


    I’m delighted with Ivory Search for being a versatile feather-weighted plugin. Loving it! Sadly I’m encountering a small problem, which I can’t find any solution from the support forum.

    I created a _nr_artist custom field for WooCommerce’s product options, using the woocommerce_product_options_general_product_data action hook. The data for this custom field is then saved into the database via the woocommerce_process_product_meta action hook. Everything works fine. However, I’m puzzled as to why Ivory Search isn’t detecting nor pulling the data from this custom field. By the way, I’m not using the Advanced Custom Fields plugin.

    Some help will be greatly appreciated. Thanks in advance.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Vinod Dalvi

    (@vinod-dalvi)

    I hope you are well today and thank you for your question.

    The plugin gets meta keys using the below query that does not fetch private custom fields so please make sure that your is not a private custom field.

    "select DISTINCT meta_key from $wpdb->postmeta pt LEFT JOIN $wpdb->posts p ON (pt.post_id = p.ID) where meta_key NOT LIKE '\_%' AND post_type IN ( '$post_type' ) ORDER BY meta_key ASC"

    Best regards,

    Thread Starter Jason Wong

    (@eljkmw)

    @vinod-dalvi Thanks for the quick response.

    Perhaps that’s why Ivory Search works well with Advanced Custom Fields plugin. Since I’ve already used the woocommerce_product_options_general_product_data action hook, is there any way to make _nr_artist custom field public so that Ivory Search can search it?

    The following is the snippet I’ve been using.

    // Display Non-Representative (NR) Artist field
    add_action( 'woocommerce_product_options_general_product_data', function() {
        // Text Field
        woocommerce_wp_text_input( 
            array( 
                'id' => '_nr_artist', 
                'label' => __( 'NR Artist', 'woocommerce' ), 
                'placeholder' => '',
                'desc_tip' => 'true',
                'description' => __( 'Enter the Non-Representative Artist\'s name, and it will override the Artist Category. Otherwise, just leave it blank.', 'woocommerce' ) 
            )
        );
    });
        
    // Save the value from the NR Artist field
    add_action( 'woocommerce_process_product_meta', function( $post_id ) {
        // Save Text Field
        $text_field = $_POST['_nr_artist'];
        if ( !empty( $text_field ) ) {
            update_post_meta( $post_id, '_nr_artist', esc_attr( $text_field ) );
        }
    });

    Please advise. Thank you.

    Plugin Author Vinod Dalvi

    (@vinod-dalvi)

    Please try removing underscore from the ID _nr_artist

    Thread Starter Jason Wong

    (@eljkmw)

    @vinod-dalvi Thank you. I must’ve forgotten having an underscore prefix turns the ID into a private custom field. I took your advice and changed everything from _nr_artist to nr_artist, and Ivory Search picked it up immediately.

    Then, in WP admin, Ivory Search > Search Forms >> Search > Products (WooCommerce), activated Search selected product custom fields values, and selected nr_artist. Click Save Form, and this custom field is searchable. Alright!

    Plugin Author Vinod Dalvi

    (@vinod-dalvi)

    You are always welcome, I’m glad I was able to help you with this matter. There is no obligation but by your kind words I wonder if I could trouble you to leave a review based on this experience here:

    https://wordpress.org/support/plugin/add-search-to-menu/reviews/

    I’d really appreciate that. 🙂

    And if I can be of any further assistance please don’t hesitate to ask.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Custom field not searched’ is closed to new replies.