BuddyDev

Search

BuddyBlog – Custom Post Type, Custom Taxonomies, and Permalinks

Tagged: 

  • Participant
    Level: Initiated
    Posts: 5
    Devin Stone on #2730

    System Info: https://codeshare.io/CfRz0
    My Custom Post Type and Taxonomy Code: https://codeshare.io/wrF6W

    Hello Brajesh,

    You helped me out immensely several months ago here: https://buddydev.com/support/forums/topic/need-to-limit-categories-users-can-post-to-in-buddyblog/

    Basically, I want to copy our previous solution, but use custom post types instead of categories to separate the official and user blogs, categories, and tags. It appears to me that this will allow for easier organizing of official and user posts, both in the front and backend. Also, I would be able to remove the “user-” prefix in the URL for all User Blog category slugs (since they will belong to a separate post type than the Official Blog).

    My plan is to have a parent navigation menu item for the Official Blog, which will include all Official Blog post types, with sub-items leading to category pages for each Official Blog category. Then have a parent navigation menu item for the User Blog (separate custom post type), with sub-items devoted to it’s category pages as well (also a custom taxonomy).

    I’ve already coded, to the best of my abilities, a custom post type and two taxonomies. I’ve selected these in the BuddyBlog settings. However, I have a few problems I need help with:

    1. The code you provided on your blog post for BuddyBlog to be used with custom post types and taxonomies, where do I place it? bpcustom? functions? I saw on the BuddyBlog admin panel that I can already select the custom post type and taxonomies I created and they appear in the user’s front end. Do I still need to this the code?

    2. My WordPress permalink settings are /%author%/%category%/%postname%/. These work fine for normal WordPress post types, but BuddyBlog custom post types by users don’t follow this. Instead, they are /user-posts/%postname%/. How do I make BuddyBlog custom post type follow my WordPress permalinks?

    3. Even with the /user-posts/%postname%/ on BuddyBlog user posts, I get a 404 error (example https://www.wingmanlocator.com/user-posts/test-user-post-3/)

    I really think that custom post types are the best way to go for what I’m trying to do, but it’s been quite frustrating getting them to work smoothly. If I can’t get this to work, I’m going to revert to the category solution we previously made, but I think it’s definitely worth a shot to make this work first.

    Please let me know your thoughts! Thanks!

    P.S. I started over with a clean WordPress install, so I don’t have any of the code currently running from the old thread, so there shouldn’t be any conflicts.

  • Keymaster
    (BuddyDev Team)
    Posts: 24593
    Brajesh Singh on #2731

    Hi Devin,
    Thank you for asking.

    1. No, You don’t need to put the code anywhere.
    2. Please visit Settings->BuddyBloog and look for the following setting

    
    
    Show single posts on user profile?
    
    

    Set it to no, and it should redirect to single post instead of user profile. That should fix both the issue.

    PS: If it is still giving 404, please visit Settings->Permalink, try to change it to something else and then change back. That will flush the permalink. When we register a post type(in general, It has nothing to do with the BuddyBlog), We need to flush the rules atleast once to make it work.

    Please do let me know if that works for you or not?

    Thank you
    Brajesh

  • Participant
    Level: Initiated
    Posts: 5
    Devin Stone on #2756

    I have already had that set to “No”. I’ve flushed permalinks as well several times. I’ve flushed them again, but no improvement.

  • Keymaster
    (BuddyDev Team)
    Posts: 24593
    Brajesh Singh on #2758

    Hi Devin,
    Is there any chance that you are using some custom code related to BuddyBlog in your bp-custom.php or your theme’s functions.php?

  • Participant
    Level: Initiated
    Posts: 5
    Devin Stone on #2765

    I took out:

    add_filter( ‘buddyblog_use_slug_in_permalink’, ‘__return_true’ );
    define( ‘BP_BUDDYBLOG_SLUG’, ‘blog’ );
    define( ‘BUDDYBLOG_ARCHIVE_SLUG’, ‘posts’ );

    And it the 404 is fixed! However, it still doesn’t follow the WordPress permalinks. For example, I made a test post titled “Test User Post” and the URL came out to https://www.wingmanlocator.com/user_posts/test-user-post/

  • Keymaster
    (BuddyDev Team)
    Posts: 24593
    Brajesh Singh on #2771

    Hi Devin,
    The only reason it is not following WordPress permalink can be somehow this filter is enabled

    
    buddyblog_show_posts_on_profile
    

    Either there is some remaining code filtering on it or somehow the admin settings for BuddyBlog to show posts on profile is still enabled.

    Please give the settings/code another check and if you don’t find anything/it does not work, Please grant me temporary access to the site. I can debug and find the problem.

    Thank you
    Brajesh

  • Participant
    Level: Initiated
    Posts: 5
    Devin Stone on #2784

    It doesn’t work I’m afraid. The Worpress posts do, but the custom type User Posts do not. I PM’d you login details.

  • Keymaster
    (BuddyDev Team)
    Posts: 24593
    Brajesh Singh on #2785

    Hi Devin,
    Thank you for the login details. I checked and it is working as expected.

    I understand that you don’t want the “user_post” in the url. It is because you have named your custom post type to “user_post”. Please see this section on codex on how to change the rewrite slug

    https://codex.wordpress.org/Function_Reference/register_post_type#rewrite

    Once you change the slug, It will use that. Please do note that the permalinks for custom post types have their own structure and will not exactly follow what is there for posts.

  • Participant
    Level: Initiated
    Posts: 5
    Devin Stone on #2799

    So BuddyBlog supports custom post types, but not custom post type permalinks? In that case, would I need to switch back to the original category approach that we originally used if I want to retain consistent permalinks?

  • Keymaster
    (BuddyDev Team)
    Posts: 24593
    Brajesh Singh on #2800

    Hi Devin,
    No That is not the case. BuddyBlog completely supports custom post type and their permalink and that is what is happening on your site.

    There is a difference between default WordPress permalinks and the permalinks for custom post type. For custom post type, you specify it using the rewrite slug at the time of registration.

    I guess you are assuming that the custom post type should use similar schema as the default posts but that is not the case. Whether you use BuddyBlog or not, that will have no effect on it.

    Can you please tell me the structure you want to use for your custom post type permalink, May be I can find some option for rewrite slug.

    Thank you
    Brajesh

You must be logged in to reply to this topic.

This topic is: not resolved