How to add a Custom-Post-Type to a Member Profile?

Hello,

I have the plugin Ultimate Member (not from your site) and the CustomPress Plugin installed. No I created a Custom-Post-Type called "Projekte". I want to include that CPT on the profile-page of the Ultimate Member Plugin. When you click on "Profil" in the Frontend, you´ll see the items "Über", "Beiträge" & "Kommentare". I just want it to show the items "Über" and "Projekte".

Could you help me to do that?

Greetings,
Marvin

  • Michelle Shull

    Hi, Marvin!

    To display your new custom post type on the user profiles, we're going to need to take a look at how your theme and membership plugin creates these profile pages. I'm assuming they work like archives, since they list all a user's posts. So, we can add something like this to your functions.php file:

    add_action( 'pre_get_posts', 'add_my_post_types_to_query' );
    
    function add_my_post_types_to_query( $query ) {
    	if ( is_archive() && $query->is_main_query() )
    		$query->set( 'post_type', array( 'post', 'projekte' ) );
    	return $query;
    }

    To hide the comments tab, let's add this to a custom CSS file:

    .um-profile-nav-item:nth-of-type(3) {
    display: none;
    }

    Do you have a custom CSS plugin? If you've got Jetpack, it comes with one; some themes include a CSS editor, or you can get a plugin, like this one: https://wordpress.org/plugins/simple-custom-css/. Or, if you're using a child theme, you can just add this to the CSS file for your child theme.

    Thanks! Hope this helps!

    • Marvin

      Hello Michelle,

      you didn´t reply to my last message.
      As mentioned, adding that to my functions.php doesn´t help. It gives back an error.

      "In the plugin directory there is a templates folder and inside that is a profile folder that contains comments-single.php, comments.php, post-single.php and post.php files. I guess a projekt-sinle.php and projekt.php will be needed here, that work the same way as the other files, I guess. But I´m not sure, as i never tweaked Wordpress like that before.

      Do you have an idea? You´ll have access to my backend to take a look."

      Greetings,
      Marvin

  • Marvin

    Hello Michelle,

    when I put your code into my functions.php, my WP-Backend and Frontend just give out an error-page.

    I use a premium-theme with a custom-css tab. So if the php-code would work, I could hide the comment-section with that.

    In the plugin directory there is a templates folder and inside that is a profile folder that contains comments-single.php, comments.php, post-single.php and post.php files. I guess a projekt-sinle.php and projekt.php will be needed here, that work the same way as the other files, I guess. But I´m not sure, as i never tweaked Wordpress like that before.

    Do you have an idea? You´ll have access to my backend to take a look.

    Greetings,
    Marvin

  • Michelle Shull

    Hi, Marvin!

    Yes, you'll need to create custom templates for your new custom post types, just as you've described here, with projekte-single.php and projekte-archive.php. I'm assuming the error you're seeing from the functions.php code I gave you is related to this.

    You do not need to add the CSS code I gave you to functions.php. It will go in the CSS editor that came with your theme.

    Here's a great guide to custom post types from our blog: https://premium.wpmudev.org/blog/create-wordpress-custom-post-types/

    Hope this helps, Marvin!

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.