WordPress.org

Ready to get started?Download WordPress

Forums

Filters - An Enhanced UI for Post management
[resolved] Add custom fields to filtering/ search results? (10 posts)

  1. ivan.marquez
    Member
    Posted 11 months ago #

    Can you help me setup your Filters plugin, so it filters/ searches for custom fied?

    http://wordpress.org/plugins/filters/

  2. Scott Kingsley Clark
    Member
    Plugin Author

    Posted 11 months ago #

    What custom fields do you want added? What types of fields are they?

  3. ivan.marquez
    Member
    Posted 11 months ago #

    I have one custom type "Directory" and it has "Country", "State", "City" and others dropdown custom types related

  4. Scott Kingsley Clark
    Member
    Plugin Author

    Posted 11 months ago #

    What's the post type name? "directory"?

    What plugin did you use to build the fields for it?

    Get me a full list of the fields you want filtered, I need the meta_key name and the label you want for it, along with the type of field.

  5. ivan.marquez
    Member
    Posted 11 months ago #

    I'm using "Ultimate Post Type Manager" (http://wordpress.org/plugins/ultimate-post-type-manager/) for creating the custom types:

    directorio (Directory)
    dire_pais (Country)
    dire_estado (State)
    dire_municipio (City)

    dire_pais, dire_estado and dire_municipio custom types are related to "directorio" using related custom fields created with "Advanced Custom Fields" plugin (http://wordpress.org/plugins/advanced-custom-fields/)

    The custom fields are:
    meta_key name: pais, type: relation, post_type: dire_pais
    meta_key name: estado, type: relation, post_type: dire_estado
    meta_key name: municipio, type: relation, post_type: dire_municipio

  6. Scott Kingsley Clark
    Member
    Plugin Author

    Posted 11 months ago #

    What do the meta values look like for the relationships? Are they IDs?

  7. ivan.marquez
    Member
    Posted 11 months ago #

    Yes, are IDs

  8. Scott Kingsley Clark
    Member
    Plugin Author

    Posted 10 months ago #

    Filters v0.3 now has Custom Field Suite support built in for it's fields, alongside the Pods integration it had before.

    I'm open to adding ACF support, can you provide the PHP used to get fields for a specific post type?

    Here's the code I added for CFS support:

    if ( is_object( $cfs ) ) {
    		$rules = array(
    			'post_types' => $post_type
    		);
    
    		$groups = $cfs->api->get_matching_groups( $rules );
    
    		$cfs_fields = array();
    		$cfs_filters = array();
    
    		if ( !empty( $groups ) ) {
    			$groups = array_keys( $groups );
    
    			$cfs_inputs = $cfs->api->find_input_fields( array( 'post_id' => $groups ) );
    
    			// needs Pods-style field array
    			if ( !empty( $cfs_inputs ) ) {
    				foreach ( $cfs_inputs as $cfs_input ) {
    					$cfs_fields[ $cfs_input[ 'name' ] ] = array(
    						'name' => $cfs_input[ 'name' ],
    						'label' => $cfs_input[ 'label' ],
    						'type' => 'text',
    						'from' => 'cfs'
    					);
    				}
    			}
    
                $cfs_filters = apply_filters( 'filters_cfs_filters', null, $groups, $cfs_inputs );
    
                if ( null === $cfs_filters || false === $cfs_filters )
                    $cfs_filters = array_keys( $cfs_fields ); // allow filters for all fields
                elseif ( empty( $filters ) )
                    $cfs_filters = array();
    		}
    
    		$fields = array_merge( $fields, $cfs_fields );
    		$filters = array_merge( $filters, $cfs_filters );
    	}
  9. biju708
    Member
    Posted 8 months ago #

    Hi your plugin is great but I am also looking into having the option of searching custom fields.

    I have 3 fields which I would like to add to the pop up screen ( or have a dropdown with all custom fields and then free text) can you kindly advise on how best to proceed. Aside from that I would also need to search by author.

    Thanks !!

  10. Scott Kingsley Clark
    Member
    Plugin Author

    Posted 8 months ago #

    This plugin isn't heavily documented, I haven't had time to put resources on it because it's actually just been isolated from the Pods project which has it's own filter handling automatically without needing for extending.

    With that said, I'll add this to my to-dos to get to you, I can't gaurantee a timeline, you may be better off looking at the code and finding the WP hook to filter the fields / filters available.

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.