Support » Plugin: Contact Form 7 - Post Fields » Filter Posts by Custom Field

  • redwolfcy

    (@redwolfcy)


    Hello,

    I have a CPT that appears on the dropdown post list.
    I want to filter those posts and show only those who have a certain ACF Field Value.

    For example, i have assigned a ACF True/False field on all posts. If the value is True, then the post should appear.

    How can we achieve this? I have read all the support posts about custom fields but did not really understand how to achieve this.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter redwolfcy

    (@redwolfcy)

    Also, since this is for a soccer related website using sportspress, we only chose to show the “Scheduled” posts, since thats what SportsPress upcoming matches post status is. Is there a way to only limit the date to always be today + 2 months? So it always shows sceduled posts from today and until the next 2 months.

    Plugin Author Markus Wiesenhofer

    (@markusfroehlich)

    Hello redwolfcy,
    yes you can use the filter wpcf7_your_tag_name_get_posts filter for this.

    Best regards
    Markus

    Thread Starter redwolfcy

    (@redwolfcy)

    @markusfroehlich can you provide an example snippet on how to achieve this?

    As mentioned above, I have read all the support posts about custom fields but did not really understand how to achieve this.

    Plugin Author Markus Wiesenhofer

    (@markusfroehlich)

    Hello redwolfcy,
    please take a look of this topic:
    https://wordpress.org/support/topic/filter-woocommerce-product-with-acf-field/

    If this topic wont solve your problem, please write me.

    Best regards
    Markus

    Thread Starter redwolfcy

    (@redwolfcy)

    Hello,

    I have added

    add_filter('wpcf7_yourtag_get_posts', 'filter_dropdown_posts');
    
    function filter_dropdown_posts($post_args){
    	$post_args['meta_query'] = array(
    		array(
    			'key' => 'show_match_in_press_accreditation',
    			'value' => 'true')
    		);
    	return $post_args; 
    }

    to my functions.php but it still brings up the same results, so it appears that the filter does not work…

    show_match_in_press_accreditation is my acf field name and it is set as True/False field.

    here is my shortcode

    [post_select post_select_59 posts-number:6 future include_blank search_box post-type:sp_event tax-relation:OR value-field:title orderby:date order:ASC "%date% - %title% - %meta_key%"]

    I have also tried changing the add_filter to
    add_filter('wpcf7_post_select_59_get_posts', 'filter_dropdown_posts');
    but gives no results at all…

    • This reply was modified 1 year ago by redwolfcy.
    • This reply was modified 1 year ago by redwolfcy.
    • This reply was modified 1 year ago by redwolfcy. Reason: show the shortcode
    • This reply was modified 1 year ago by redwolfcy.
    Plugin Author Markus Wiesenhofer

    (@markusfroehlich)

    Please check, if the filter works:

    
    add_filter('wpcf7_'.$tag_name.'_get_posts', 'filter_dropdown_posts', 10, 3);
    
    function filter_dropdown_posts($post_args, $tag, $args)
    {
    print_r($post_args);
    return $post_args;
    }
    

    Best regards
    Markus

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Filter Posts by Custom Field’ is closed to new replies.