Okay
  Public Ticket #1225619
Comparing Custom Fields of same Listings Fails
Closed

Comments

  • Avancer Warehouses started the conversation

    Hi,

    I have created new listings with custom fields and metaboxes. However when I compare them, I see no fields getting compared. (Image attached).

    How can I add custom fields to be compared?

    Attached files:  issue2.png

  •  76
    Erik replied

    Hi. The comparator does not know which custom fields you want to compare. You need to explicitly declare them using WP filter inventor_compare_fields

    http://inventorwp.com/documentation/developer-guide/filters.html

  • Avancer Warehouses replied

    Hi,

    Thanks for the pointer. I understand your point. However, I am not able to understand how to work with this filter code (add filter/ apply filter...?).

    Could you please point out few steps/code sample on how to do add custom fields for comparing. 

  •  76
    Erik replied

    Hi. It is a regular WP filter which excepts to return an associative array of field identifiers and their titles.

  • Avancer Warehouses replied

    Thanks for the help Erik, I was able to add comparision for Listing category A.

    Now how do i send different Fields for listing type B. I tired the below method but it doesn't work.

    add_filter( 'inventor_compare_fields', function( $fields) {

            $post_type = get_post_type( $listing_id );  
            if($post_type=='cars')
            {     return array( ......................);      }

           else if ($post_type=='bus')

          {       return array( ......................);      }

     I understand this method is wrong. Could you please provide right method.

  •  76
    Erik replied

    Your $listing_id variable is always empty. You can access the comparing listings by calling this helper:

    $listings_ids = Inventor_Compare_Logic::get_comparison_list();

    It will return the list of listing identifiers in the comparison list. Then you can check the post type of each compared listing.

    Hope it helps.