Public Ticket #1225619
Comparing Custom Fields of same Listings Fails


  • Avancer Warehouses started the conversation


    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

  •  89
    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


  • Avancer Warehouses replied


    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. 

  •  89
    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 );  
            {     return array( ......................);      }

           else if ($post_type=='bus')

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

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

  •  89
    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.

  • jbcrouigneau replied


    I tried something like this :

    add_filter( 'inventor_compare_fields', function($fields) {
            return array("licence_type"=>"Licence Type", "status"=>"Status");
    } );

    I can see two lines in comparaison table, called "Licence Type" and "Status", but no values (when selected items have values, of course).

    What is wrong with my code?

    Notice: I use only one listing type, a custom listing type.

    Best regards.

  •  89
    Erik replied

    Hi. You need to put the whole listing field identifier:

    So not "licence_type", but "listing_licence_type" and not "status", but "listing_status".