Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Eyal Fitoussi

    (@ninjew)

    HI,
    You can try the script below ( added to the functions.php file of the theme ). Then replace the values of $taxonomy and $term_slug based on your needs.

    function gmw_filter_form_by_cateogry_page( $tax_args, $gmw ) {
    
            // enter the taxonomy slug for example 'directory_categories'
            $taxonomy = 'directory_categories;
    
            // enter the term slug that you'd like to display. For example 'wine_and_dining'
             $term_slug = 'wine_and_dining';
    
    	// create the filter based on taxonomy and terms ID
    	$tax_args = array(
    		array(
    			'taxonomy' => $taxonomy,
    			'field'          => 'slug',
    			'terms'       => $term_slug,
    		)
    	);
    
    	return $tax_args;
    }
    add_filter(  'gmw_pt_tax_query', 'gmw_filter_form_by_cateogry_page', 90, 2 );
    Thread Starter krm218

    (@krm218)

    filter_form_by_cateogry & gmw_filter_form_by_cateogry_page

    is this meant to be category instead of cateogry?

    Also, what is this line doing in the code?
    add_filter( 'gmw_pt_tax_query', 'gmw_filter_form_by_cateogry_page', 90, 2 );

    Will this apply to all of the forms or just [gmw form=”1″] and I can just put that code in the page?

    Thank you for your help.

    Thread Starter krm218

    (@krm218)

    Any updates on this issue?

    Thank you!

    Plugin Author Eyal Fitoussi

    (@ninjew)

    HI,

    is this meant to be category instead of cateogry?

    Yes, it is a typo and you can fix it. But it should have still worked this way.

    Also, what is this line doing in the code?
    add_filter( ‘gmw_pt_tax_query’, ‘gmw_filter_form_by_cateogry_page’, 90, 2 );

    gmw_pt_tax_query is a filter that executes the function gmw_filter_form_by_cateogry_page(). The function should change the value of the taxonomy argument.

    Here you can read more and learn about WordPress hooks ( actions and filters ).

    Will this apply to all of the forms or just [gmw form=”1″]

    The above will apply to all forms. You can limit it to a specific form, for example form with ID 1, using the below:

    function gmw_filter_form_by_cateogry_page( $tax_args, $gmw ) {
    
            if ( $gmw['ID'] != 1 ) {
                return $tax_args;
            }
    
            // enter the taxonomy slug for example 'directory_categories'
            $taxonomy = 'directory_categories;
    
            // enter the term slug that you'd like to display. For example 'wine_and_dining'
             $term_slug = 'wine_and_dining';
    
    	// create the filter based on taxonomy and terms ID
    	$tax_args = array(
    		array(
    			'taxonomy' => $taxonomy,
    			'field'          => 'slug',
    			'terms'       => $term_slug,
    		)
    	);
    
    	return $tax_args;
    }
    add_filter(  'gmw_pt_tax_query', 'gmw_filter_form_by_cateogry_page', 90, 2 );

    and I can just put that code in the page?

    You need to add the code to the functions.php file of your theme or child theme and change the value of $taxonomy and $term_slug in the function based on your needs.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to display a certain category from a form’ is closed to new replies.