Skip to:
Content
Pages
Categories
Search
Top
Bottom

Get_Forum_Name from functions.php


  • ttiefenbach
    Participant

    @ttiefenbach

    I’m trying to get a default featured image to display using a filter of “post_thumbnail_id” in my child theme’s functions.php file. I’m able to add a default thumbnail for post_type of topic, but I’d like it to be a custom thumbnail based on the id, or name of the forum the topic is in. Here’s what I have so far:

    function my_filter_thumbnail_id( $thumbnail_id, $post = null ) {
    	if ( $post->post_type != 'topic' )
    		return $thumbnail_id;
    	
    	$forumname = get_forum_name( $post->forum_id );
    	if ( $forumname == "wellness")
    		$thumbnail_id = 7091;
    
    	return  $thumbnail_id;
    }
    add_filter( 'post_thumbnail_id', 'my_filter_thumbnail_id', 20, 5 );
    

    The issue is, “get_forum_name(),” is an undefined function. I’m not looking to override the default functions of bbPress, just be able to access the forum_id or forum_name from my theme’s functions.php file. Any help would be greatly appreciated! Thanks

Viewing 2 replies - 1 through 2 (of 2 total)

  • Robin W
    Moderator

    @robin-w

    $forumname = bbp_get_forum_title( $post->forum_id );


    ttiefenbach
    Participant

    @ttiefenbach

    Thanks for the quick reply! Unfortunately, your code returned the topic’s title.

    That allowed me to narrow my search, though, and I was able to get the correct functions for my permalink structure:

    function my_filter_thumbnail_id( $thumbnail_id, $post = null ) {
    	if ( $post->post_type != 'topic' )
    		return $thumbnail_id;
    	
    	$forumid = bbp_get_topic_forum_id();
    	if ( $forumid == 6728 )
    		$thumbnail_id = 7091;
    
    	return  $thumbnail_id;
    }
    add_filter( 'post_thumbnail_id', 'my_filter_thumbnail_id', 20, 5 );
    

    I could probably use the bbp_get_forum_title() function to get the tiel to compare, like you suggested, but I went with just validating the ID since it was working.

    Thanks for your help!!

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