Okay
  Public Ticket #1640009
Filters not working on custom post type/fields created by Toolset plugin
Closed

Comments

  •  3
    kenkitchen started the conversation

    I have built a data table against a custom post type, listing custom metadata fields.  The posts are created using the Toolset plugin.  Everything about the table seems fine...except that the filters are not working.  Both the simple and the advanced ones just come up empty, with no error message that I can find.

  •  471
    Isidora replied

    Hi kenkitchen,
    Thank you for your purchase.

    If your MySQL-query based wpDataTable doesn’t work correctly with server-side processing, probably this is happening because wpDataTables server has problems with parsing of the query and building new queries dynamically (happens rarely, but does sometimes). To avoid this please prepare a MySQL view (a stored query), which will return the data that you need, call it e.g. “view1” and then build a wpDataTabled based on a simple query like “SELECT * FROM view1″.

    Kind Regards, 

    Isidora Markovic

    wpDataTables: FAQFacebookTwitterFront-end and back-end demoDocs

    Amelia: FAQFacebookTwitter |  Amelia demo sites | Docs

    You can try our wpDataTables add-ons before purchase on these sandbox sites:

    Powerful FiltersGravity Forms Integration for wpDataTablesFormidable Forms Integration for wpDataTables

  •  3
    kenkitchen replied

    The datatable builds the query correctly, and provides the correct results.  The only problem is with the column filters: Any filter value, in any column, returns No Records Found.

    I understood that the datatable at that point would be looking at the HTML table, finished with the SQL work.  Is that not correct?

    I cannot feasibly make a View because the FROM clause contains several sub-queries.  MySQL does not allow sub-queries in Views (https://stackoverflow.com/questions/17983379/mysql-error-1349-what-i-am-missing).  I hope to fix whatever I have wrong with the filters without having to change the SQL, if possible.

  •  3
    kenkitchen replied

    Another note: The same misbehavior happens on the main Search block, as well.  The issue is not limited to just the advanced column filters.

  •  471
    Isidora replied

    Hi kenkitchen,

    Unfortunately if you are using complicated queries you have to make view from that query so serverside processing (searching and filtering) will work correctly. When serverside is turn on when you use search of filtering it will be send ajax calls to the backend which build queries that return results based on your input. If you don't have large amount of data in table(less the 1000 rows ) you can turn off server side processing and then filtering and searching will do javascript logic on page.

    Kind Regards, 

    Isidora Markovic

    wpDataTables: FAQFacebookTwitterFront-end and back-end demoDocs

    Amelia: FAQFacebookTwitter |  Amelia demo sites | Docs

    You can try our wpDataTables add-ons before purchase on these sandbox sites:

    Powerful FiltersGravity Forms Integration for wpDataTablesFormidable Forms Integration for wpDataTables

  •  3
    kenkitchen replied

    OK, I was able to get the query re-worked.  The filters are fine now.  You can close the ticket.  Thanks!

    FFR, see below for the two versions of the query.  "From" was built for me by WPDataTables.  It used sub-queries to get each of the several custom metadata fields.  "To" does the same thing, but moves the sub-queries to the SELECT instead of the FROM clause.  MySQL allows views to be created from that.  :-)


    ----------------------- FROM -------------------
    SELECT posts_container.ID AS container_ID,
           posts_container.post_date AS container_post_date,
           CONCAT('<a href="/containers/container/',posts_container.post_title,'/?layout_id=1198">Edit</a>') AS edit_link,
           posts_container.post_title AS serial_nbr,
           container_meta_wpcf_container_type_tbl.meta_value AS container_meta_wpcf_container_type,
           container_meta_wpcf_manufacturer_tbl.meta_value AS container_meta_wpcf_manufacturer,
           container_meta_wpcf_property_type_tbl.meta_value AS container_meta_wpcf_property_type,
          posts_container.post_modified AS container_post_modified,
           posts_container_author.display_name AS container_post_author,
          container_meta_wpcf_apt_unit_tbl.meta_value AS apt_unit,
           container_meta_wpcf_address_tbl.meta_value AS container_meta_wpcf_address,
           container_meta_wpcf_container_comments_text_tbl.meta_value AS container_meta_wpcf_container_comments_text,
           CONCAT('<img src="',container_meta_wpcf_container_image_tbl.meta_value,'" height="75px" width="75px">') AS container_meta_wpcf_container_image,
           container_meta_wpcf_geo_house_tbl.meta_value AS house,
           container_meta_wpcf_geo_street_tbl.meta_value AS street,
           container_meta_wpcf_geo_city_tbl.meta_value AS city,
           container_meta_wpcf_geo_state_tbl.meta_value AS state,
           container_meta_wpcf_geo_zipcode_tbl.meta_value AS zip_code,
           container_meta_wpcf_geo_country_tbl.meta_value AS country
    FROM wp_12_posts AS posts_container
      left JOIN wp_users AS posts_container_author
         ON posts_container_author.ID = posts_container.post_author
      left JOIN (SELECT container_meta_wpcf_address_tbl_posts.ID as id, meta_value, meta_key  FROM wp_12_postmeta AS container_meta_wpcf_address_tbl_postmeta  INNER JOIN wp_12_posts AS container_meta_wpcf_address_tbl_posts   ON container_meta_wpcf_address_tbl_postmeta.post_id = container_meta_wpcf_address_tbl_posts.ID   AND container_meta_wpcf_address_tbl_posts.post_type = 'container') AS container_meta_wpcf_address_tbl
         ON container_meta_wpcf_address_tbl.meta_key = 'wpcf-address' AND container_meta_wpcf_address_tbl.id = posts_container.ID 
      left JOIN (SELECT container_meta_wpcf_container_comments_text_tbl_posts.ID as id, meta_value, meta_key  FROM wp_12_postmeta AS container_meta_wpcf_container_comments_text_tbl_postmeta  INNER JOIN wp_12_posts AS container_meta_wpcf_container_comments_text_tbl_posts   ON container_meta_wpcf_container_comments_text_tbl_postmeta.post_id = container_meta_wpcf_container_comments_text_tbl_posts.ID   AND container_meta_wpcf_container_comments_text_tbl_posts.post_type = 'container') AS container_meta_wpcf_container_comments_text_tbl
         ON container_meta_wpcf_container_comments_text_tbl.meta_key = 'wpcf-container-comments-text' AND container_meta_wpcf_container_comments_text_tbl.id = posts_container.ID 
      left JOIN (SELECT container_meta_wpcf_container_image_tbl_posts.ID as id, meta_value, meta_key  FROM wp_12_postmeta AS container_meta_wpcf_container_image_tbl_postmeta  INNER JOIN wp_12_posts AS container_meta_wpcf_container_image_tbl_posts   ON container_meta_wpcf_container_image_tbl_postmeta.post_id = container_meta_wpcf_container_image_tbl_posts.ID   AND container_meta_wpcf_container_image_tbl_posts.post_type = 'container') AS container_meta_wpcf_container_image_tbl
         ON container_meta_wpcf_container_image_tbl.meta_key = 'wpcf-container-image' AND container_meta_wpcf_container_image_tbl.id = posts_container.ID 
      left JOIN (SELECT container_meta_wpcf_container_type_tbl_posts.ID as id, meta_value, meta_key  FROM wp_12_postmeta AS container_meta_wpcf_container_type_tbl_postmeta  INNER JOIN wp_12_posts AS container_meta_wpcf_container_type_tbl_posts   ON container_meta_wpcf_container_type_tbl_postmeta.post_id = container_meta_wpcf_container_type_tbl_posts.ID   AND container_meta_wpcf_container_type_tbl_posts.post_type = 'container') AS container_meta_wpcf_container_type_tbl
         ON container_meta_wpcf_container_type_tbl.meta_key = 'wpcf-container-type' AND container_meta_wpcf_container_type_tbl.id = posts_container.ID 
      left JOIN (SELECT container_meta_wpcf_manufacturer_tbl_posts.ID as id, meta_value, meta_key  FROM wp_12_postmeta AS container_meta_wpcf_manufacturer_tbl_postmeta  INNER JOIN wp_12_posts AS container_meta_wpcf_manufacturer_tbl_posts   ON container_meta_wpcf_manufacturer_tbl_postmeta.post_id = container_meta_wpcf_manufacturer_tbl_posts.ID   AND container_meta_wpcf_manufacturer_tbl_posts.post_type = 'container') AS container_meta_wpcf_manufacturer_tbl
         ON container_meta_wpcf_manufacturer_tbl.meta_key = 'wpcf-manufacturer' AND container_meta_wpcf_manufacturer_tbl.id = posts_container.ID 
      left JOIN (SELECT container_meta_wpcf_property_type_tbl_posts.ID as id, meta_value, meta_key  FROM wp_12_postmeta AS container_meta_wpcf_property_type_tbl_postmeta  INNER JOIN wp_12_posts AS container_meta_wpcf_property_type_tbl_posts   ON container_meta_wpcf_property_type_tbl_postmeta.post_id = container_meta_wpcf_property_type_tbl_posts.ID   AND container_meta_wpcf_property_type_tbl_posts.post_type = 'container') AS container_meta_wpcf_property_type_tbl
         ON container_meta_wpcf_property_type_tbl.meta_key = 'wpcf-property-type' AND container_meta_wpcf_property_type_tbl.id = posts_container.ID 
      left JOIN (SELECT container_meta_wpcf_geo_zipcode_tbl_posts.ID as id, meta_value, meta_key  FROM wp_12_postmeta AS container_meta_wpcf_geo_zipcode_tbl_postmeta  INNER JOIN wp_12_posts AS container_meta_wpcf_geo_zipcode_tbl_posts   ON container_meta_wpcf_geo_zipcode_tbl_postmeta.post_id = container_meta_wpcf_geo_zipcode_tbl_posts.ID   AND container_meta_wpcf_geo_zipcode_tbl_posts.post_type = 'container') AS container_meta_wpcf_geo_zipcode_tbl
         ON container_meta_wpcf_geo_zipcode_tbl.meta_key = 'wpcf-geo-zipcode' AND container_meta_wpcf_geo_zipcode_tbl.id = posts_container.ID 
      left JOIN (SELECT container_meta_wpcf_geo_house_tbl_posts.ID as id, meta_value, meta_key  FROM wp_12_postmeta AS container_meta_wpcf_geo_house_tbl_postmeta  INNER JOIN wp_12_posts AS container_meta_wpcf_geo_house_tbl_posts   ON container_meta_wpcf_geo_house_tbl_postmeta.post_id = container_meta_wpcf_geo_house_tbl_posts.ID   AND container_meta_wpcf_geo_house_tbl_posts.post_type = 'container') AS container_meta_wpcf_geo_house_tbl
         ON container_meta_wpcf_geo_house_tbl.meta_key = 'wpcf-geo-house' AND container_meta_wpcf_geo_house_tbl.id = posts_container.ID 
      left JOIN (SELECT container_meta_wpcf_geo_street_tbl_posts.ID as id, meta_value, meta_key  FROM wp_12_postmeta AS container_meta_wpcf_geo_street_tbl_postmeta  INNER JOIN wp_12_posts AS container_meta_wpcf_geo_street_tbl_posts   ON container_meta_wpcf_geo_street_tbl_postmeta.post_id = container_meta_wpcf_geo_street_tbl_posts.ID   AND container_meta_wpcf_geo_street_tbl_posts.post_type = 'container') AS container_meta_wpcf_geo_street_tbl
         ON container_meta_wpcf_geo_street_tbl.meta_key = 'wpcf-geo-street' AND container_meta_wpcf_geo_street_tbl.id = posts_container.ID 
      left JOIN (SELECT container_meta_wpcf_geo_city_tbl_posts.ID as id, meta_value, meta_key  FROM wp_12_postmeta AS container_meta_wpcf_geo_city_tbl_postmeta  INNER JOIN wp_12_posts AS container_meta_wpcf_geo_city_tbl_posts   ON container_meta_wpcf_geo_city_tbl_postmeta.post_id = container_meta_wpcf_geo_city_tbl_posts.ID   AND container_meta_wpcf_geo_city_tbl_posts.post_type = 'container') AS container_meta_wpcf_geo_city_tbl
         ON container_meta_wpcf_geo_city_tbl.meta_key = 'wpcf-geo-city' AND container_meta_wpcf_geo_city_tbl.id = posts_container.ID 
      left JOIN (SELECT container_meta_wpcf_geo_state_tbl_posts.ID as id, meta_value, meta_key  FROM wp_12_postmeta AS container_meta_wpcf_geo_state_tbl_postmeta  INNER JOIN wp_12_posts AS container_meta_wpcf_geo_state_tbl_posts   ON container_meta_wpcf_geo_state_tbl_postmeta.post_id = container_meta_wpcf_geo_state_tbl_posts.ID   AND container_meta_wpcf_geo_state_tbl_posts.post_type = 'container') AS container_meta_wpcf_geo_state_tbl
         ON container_meta_wpcf_geo_state_tbl.meta_key = 'wpcf-geo-state' AND container_meta_wpcf_geo_state_tbl.id = posts_container.ID 
      left JOIN (SELECT container_meta_wpcf_geo_country_tbl_posts.ID as id, meta_value, meta_key  FROM wp_12_postmeta AS container_meta_wpcf_geo_country_tbl_postmeta  INNER JOIN wp_12_posts AS container_meta_wpcf_geo_country_tbl_posts   ON container_meta_wpcf_geo_country_tbl_postmeta.post_id = container_meta_wpcf_geo_country_tbl_posts.ID   AND container_meta_wpcf_geo_country_tbl_posts.post_type = 'container') AS container_meta_wpcf_geo_country_tbl
         ON container_meta_wpcf_geo_country_tbl.meta_key = 'wpcf-geo-country' AND container_meta_wpcf_geo_country_tbl.id = posts_container.ID 
      left JOIN (SELECT container_meta_wpcf_apt_unit_tbl_posts.ID as id, meta_value, meta_key  FROM wp_12_postmeta AS container_meta_wpcf_apt_unit_tbl_postmeta  INNER JOIN wp_12_posts AS container_meta_wpcf_apt_unit_tbl_posts   ON container_meta_wpcf_apt_unit_tbl_postmeta.post_id = container_meta_wpcf_apt_unit_tbl_posts.ID   AND container_meta_wpcf_apt_unit_tbl_posts.post_type = 'container') AS container_meta_wpcf_apt_unit_tbl
         ON container_meta_wpcf_apt_unit_tbl.meta_key = 'wpcf-apt-unit' AND container_meta_wpcf_apt_unit_tbl.id = posts_container.ID 
    WHERE 1=1 
       AND posts_container.post_type = 'container'
       and posts_container.post_title not like 'CRED%'
       order by posts_container.post_date DESC
       
       
       ------------------- TO ------------------
       create or replace view wp_12_container_view as
          SELECT posts_container.ID AS container_ID,
           posts_container.post_type as post_type,
           CONCAT('<a href="/containers/container/',posts_container.post_title,'/?layout_id=1198">Edit</a>') AS edit_link,
           posts_container.post_title AS serial_nbr,
           posts_container.post_date AS container_post_date,
          posts_container.post_modified AS container_post_modified,
          posts_container_author.display_name AS container_post_author,
         (SELECT meta_value  FROM wp_12_postmeta WPMeta_container_type INNER JOIN wp_12_posts WPPost_container_type ON WPMeta_container_type.post_id = WPPost_container_type.ID   
          WHERE WPPost_container_type.post_type = 'container' AND WPPost_container_type.ID = posts_container.ID
               AND WPMeta_container_type.meta_key = 'wpcf-container-type' ) AS container_meta_wpcf_container_type,
          (SELECT meta_value  FROM wp_12_postmeta WPMeta_manufacturer INNER JOIN wp_12_posts WPPost_manufacturer ON WPMeta_manufacturer.post_id = WPPost_manufacturer.ID   
           WHERE WPPost_manufacturer.post_type = 'container' AND WPPost_manufacturer.ID = posts_container.ID
                AND WPMeta_manufacturer.meta_key = 'wpcf-manufacturer' ) AS container_meta_wpcf_manufacturer,
           (SELECT meta_value  FROM wp_12_postmeta WPMeta_property_type INNER JOIN wp_12_posts WPPost_property_type ON WPMeta_property_type.post_id = WPPost_property_type.ID   
            WHERE WPPost_property_type.post_type = 'container' AND WPPost_property_type.ID = posts_container.ID
                AND WPMeta_property_type.meta_key = 'wpcf-property-type' ) AS container_meta_wpcf_property_type,
          (SELECT meta_value  FROM wp_12_postmeta WPMeta_Address INNER JOIN wp_12_posts WPPost_Address ON WPMeta_Address.post_id = WPPost_Address.ID   
           WHERE WPPost_Address.post_type = 'container'  AND WPPost_Address.ID = posts_container.ID
                AND WPMeta_Address.meta_key = 'wpcf-address' ) AS container_meta_wpcf_address,
          (SELECT meta_value  FROM wp_12_postmeta WPMeta_apt_unit INNER JOIN wp_12_posts WPPost_apt_unit ON WPMeta_apt_unit.post_id = WPPost_apt_unit.ID   
           WHERE WPPost_apt_unit.post_type = 'container' AND WPPost_apt_unit.ID = posts_container.ID
                AND WPMeta_apt_unit.meta_key = 'wpcf-apt-unit' ) AS container_meta_wpcf_apt_unit,
          (SELECT meta_value  FROM wp_12_postmeta WPMeta_container_comments_text INNER JOIN wp_12_posts WPPost_container_comments_text ON WPMeta_container_comments_text.post_id = WPPost_container_comments_text.ID   
           WHERE WPPost_container_comments_text.post_type = 'container'  AND WPPost_container_comments_text.ID = posts_container.ID
                AND WPMeta_container_comments_text.meta_key = 'wpcf-container-comments-text' )  AS container_meta_wpcf_comments_text,
          (SELECT meta_value  FROM wp_12_postmeta WPMeta_container_image INNER JOIN wp_12_posts WPPost_container_image ON WPMeta_container_image.post_id = WPPost_container_image.ID   
          WHERE WPPost_container_image.post_type = 'container' AND WPPost_container_image.ID = posts_container.ID
                AND WPMeta_container_image.meta_key = 'wpcf-container-image' )   AS container_meta_wpcf_container_image,
          (SELECT meta_value  FROM wp_12_postmeta WPMeta_geo_house INNER JOIN wp_12_posts WPPost_geo_house ON WPMeta_geo_house.post_id = WPPost_geo_house.ID   
           WHERE WPPost_geo_house.post_type = 'container'  AND WPPost_geo_house.ID = posts_container.ID
               AND WPMeta_geo_house.meta_key = 'wpcf-geo-house' ) AS container_meta_wpcf_geo_house,
          (SELECT meta_value  FROM wp_12_postmeta WPMeta_geo_street INNER JOIN wp_12_posts WPPost_geo_street ON WPMeta_geo_street.post_id = WPPost_geo_street.ID   
           WHERE WPPost_geo_street.post_type = 'container' AND WPPost_geo_street.ID = posts_container.ID
                AND WPMeta_geo_street.meta_key = 'wpcf-geo-street' ) AS container_meta_wpcf_geo_street,
          (SELECT meta_value  FROM wp_12_postmeta WPMeta_geo_city INNER JOIN wp_12_posts WPPost_geo_city ON WPMeta_geo_city.post_id = WPPost_geo_city.ID   
           WHERE WPPost_geo_city.post_type = 'container'  AND WPPost_geo_city.ID = posts_container.ID
                AND WPMeta_geo_city.meta_key = 'wpcf-geo-city' ) AS container_meta_wpcf_geo_city,
          (SELECT meta_value  FROM wp_12_postmeta WPMeta_geo_state INNER JOIN wp_12_posts WPPost_geo_state ON WPMeta_geo_state.post_id = WPPost_geo_state.ID   
           WHERE WPPost_geo_state.post_type = 'container'  AND WPPost_geo_state.ID = posts_container.ID
                AND WPMeta_geo_state.meta_key = 'wpcf-geo-state' )  AS container_meta_wpcf_geo_state,
          (SELECT meta_value  FROM wp_12_postmeta WPMeta_geo_zipcode INNER JOIN wp_12_posts WPPost_geo_zipcode ON WPMeta_geo_zipcode.post_id = WPPost_geo_zipcode.ID   
          WHERE WPPost_geo_zipcode.post_type = 'container'  AND WPPost_geo_zipcode.ID = posts_container.ID
                AND WPMeta_geo_zipcode.meta_key = 'wpcf-geo-zipcode' ) AS container_meta_wpcf_geo_zipcode,
          (SELECT meta_value  FROM wp_12_postmeta WPMeta_geo_country INNER JOIN wp_12_posts WPPost_geo_country ON WPMeta_geo_country.post_id = WPPost_geo_country.ID   
          WHERE WPPost_geo_country.post_type = 'container'  AND WPPost_geo_country.ID = posts_container.ID
                AND WPMeta_geo_country.meta_key = 'wpcf-geo-country' ) AS container_meta_wpcf_geo_country
    FROM wp_12_posts AS posts_container
      left JOIN wp_users AS posts_container_author
         ON posts_container_author.ID = posts_container.post_author
    WHERE 1=1 
       AND posts_container.post_type = 'container'
       and posts_container.post_title not like 'CRED%'
       order by posts_container.post_date DESC    


  •  471
    Isidora replied

    Hi kenkitchen,

    I am glad that you found a solution and share it with us, so other users that have same issue can find it and resolve the issue like you do. Nice job!

    Best regards.

    Kind Regards, 

    Isidora Markovic

    wpDataTables: FAQFacebookTwitterFront-end and back-end demoDocs

    Amelia: FAQFacebookTwitter |  Amelia demo sites | Docs

    You can try our wpDataTables add-ons before purchase on these sandbox sites:

    Powerful FiltersGravity Forms Integration for wpDataTablesFormidable Forms Integration for wpDataTables