Advanced Location: Unable to get custom function to work

Support MB Include Exclude Advanced Location: Unable to get custom function to workResolved

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #39880
    AJ TatumAJ Tatum
    Participant

    I want a metabox to show only if the post type is 'podcast' OR if the post type is 'post' and a custom field, 'is_ajtd_podcast', is true.

    So, in the meta box for the field group 'podcast-fields', I have nothing selected for Location and for "Advanced Location" I have it to show when all conditions match and have custom set to ajtd_show_podcast_fields.

    In my functions.php, I've tried many ways to get this to work, but here is my function:

    function ajtd_show_podcast_fields($meta_box) {
        $show = false;
    	$post_id = isset($_GET['post']) ? $_GET['post'] : null;
    	if($post_id != null)
    	{
    		$pts = array('post','podcast');
    		$pt = get_post_type($post_id);
    		$is_podcast = get_post_meta($post_id, 'is_ajtd_podcast', true);
    		if ($pt == 'podcast' || ($pt == 'post' && $is_podcast = true)) {
    			$show = true;
    		}	
    	}
        return $show;
    };

    This doesn't seem to do anything as the custom fields show up no matter what.

    I've tried a variation based on https://docs.metabox.io/filters/rwmb-show/

    and had the same logic, but the filter as:

    add_filter( 'rwmb_show_podcast-fields', function( $show, $meta_box )

    However, when I tried to add that to functions.php, it would throw an error.

    #39881
    AJ TatumAJ Tatum
    Participant

    LOL, it wasn't until I posted this that I realized I made a stupid mistake and had the logic '$is_podcast = true' when it should have been ==. That fixed it.

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.