Skip to:

Custom Component Help

  • stoi2m1


    I have built a custom component called music and it uses a custom post type called music. I can display the component and its archive on the Page I created called music just fine, but when I try to display the single post item I have either been getting a 500 error or a 404 error. Things only seem to work when I make the slug for the rewrite as track instead of music. Can some one help me get the permalink to my single posts working?

    I once had all of this working but have been working on a rewrite of my theme and I seem to have broken things.

    I used BP skeleton to write the component and a tutorial on the development of bp-checkins to get most of my component working.

    I am also looking to add in a custom taxonomy into the permalink structure. Any feedback on how to accomplish this as well would be much appreciated.


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

  • shanebp


    Might be related to your component, but probably just the usual cpt issues.

    Do you have a theme template called single-music.php so that WP can display it?

    Do you have a pre_get_posts filter in your theme/functions.php or plugin file so that WP knows you want a cpt?

    // so music cpt is included in cat or tag calls
    function stoi_query_post_type($query) {
      if(is_category() || is_tag()) {
        $post_type = get_query_var('post_type');
    	    $post_type = $post_type;
    	    $post_type = array('post','music');
    	return $query;
    add_filter('pre_get_posts', 'stoi_query_post_type');



    I dont have a pre_get_posts for other post types I have defined, but those also do not have a bp component associated with them (those display just fine). I do not have a single-music.php file nor do I have a single-track.php file, however when I change my slug to track all is good. Like I said all of this worked in a previous theme I was using but now that I am writing a new theme things are not working for my single posts only for this custom post type which has an associated bp component and a page called music which this component is associated with.




    I found that my custom post type and page Im using for the archive have the same slug. I have read in various places that this commonly causes a 404 error. I added a submenu item for single posts to display under the pages slug like so.

    $single_item_link = $bp->current_item;
    if ( bp_is_my_custom_component() && bp_is_single_item() ) {
    	// Reset sub nav
    	$sub_nav = array();
    	// Add single music page but dont display in navigation
    	$main_nav = array(
    		'name'                => __( 'Single Music', 'bp-music' ),
    		'slug'                => $single_item_link,
    		'position'            => -1, // Do not show in BuddyBar
    		'screen_function'     => 'custom_component_screen_single',
    		'default_subnav_slug' => $this->default_extension,
    		'item_css_id'         => $this->id

    This menu item loads a function in the screens file of the component

    function custom_component_screen_single() {
    	if ( ! bp_is_single_item() )
    		return false;
    	$bp = buddypress();
    	do_action( 'custom_component_screen_single' );
    	bp_core_load_template( apply_filters( 'custom_component_screen_single', 'custom-component/single/home' ) ); //this loads a template file within the template folder of the component or within the theme

    And for now all is good. I would still like to find a way to load my custom taxonomy into the permalink structure so things would look like this.

    If anyone has any ideas on how I can get this to work as well please let me know. My guess is I could make another menu item to capture that instance and if the genre exists then it loads a template file. Then I need to find a way to make sure a single item and a custom taxanomy dont end up with the same name.


Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Custom Component Help’ is closed to new replies.
Skip to toolbar