How to change the post type on Ultimate Member posts tab

Get access to all plugins for $99 with our All Access Lifetime Suite!

In this quick tutorial, one will learn how to make a quick way to change the post type on the posts tab from post to any other post type including a custom post type.

In a previous tutorial;  How to customize Ultimate Member templates, one learnt how to override UM templates. If you have not read it, it is a good idea to take a look before proceeding.

Updated version test with minimum Ultimate Member version 2.0.43

In your child-theme or a custom plugin, add the following snippet

function custom_um_profile_query_make_posts( $args = array() ) {

    // Change the post type to our liking.

    $args['post_type'] = 'page';

    return $args;

}

add_filter( 'um_profile_query_make_posts', 'custom_um_profile_query_make_posts', 12, 1 );

What this does is hook into the filter um_profile_query_make_posts  and change the settings for the posts query. You can add different arguments for the query by looking at what is available for WP_Query

Do not use the following code unless you using an older version of Ultimate Member

Step 1: Copy file to theme

For this tutorial, we are going to customize the posts.php file. Let’s setup our overriding folders and file. Inside of your theme create the following folders ultimate-member -> templates -> profile

Copy the file yourtheme-> ultimate-member -> templates -> profile -> posts.php to the previous created folder.

Step 2: Edit the file

Use the following code if you are using Ultimate Member 2.0+

Open the posts.php file using an IDE of notepad. Locate the line that has following

<?php $query_posts = UM()->query()->make('post_type=post&posts_per_page=10&offset=0&author=' . um_user('ID') ); ?>

After post_type=, change the word post to the post type that you would like for example um_story

<?php $query_posts = UM()->query()->make('post_type=um_story&posts_per_page=10&offset=0&author=' . um_user('ID') ); ?>

Next, let’s change the post type for the load more area. Find the line of the code that has the following

 <a href="#" class="um-ajax-paginate um-button" data-hook="um_load_posts" data-args="post,10,10,<?php echo um_user('ID'); ?>"><?php _e('load more posts','ultimatemember'); ?></a>

Where it says post,10,10 change post to the post type that you would like for example um_story,10,10

 <a href="#" class="um-ajax-paginate um-button" data-hook="um_load_posts" data-args="um_story,10,10,<?php echo um_user('ID'); ?>"><?php _e('load more posts','ultimatemember'); ?></a>

Save the file and there you have it. If you have followed the steps as mentioned here, you should now have a list of another post type.

Prior to Ultimate Member 2.0

Open the posts.php file using an IDE of notepad. Locate the line that has following

<?php $query_posts = $ultimatemember->query->make('post_type=post&posts_per_page=10&offset=0&author=' . um_user('ID') ); ?>

After post_type=, change the word post to the post type that you would like for example um_story

<?php $query_posts = $ultimatemember->query->make('post_type=um_story&posts_per_page=10&offset=0&author=' . um_user('ID') ); ?>

Next, let’s change the post type for the load more area. Find the line of the code that has the following

 <a href="#" class="um-ajax-paginate um-button" data-hook="um_load_posts" data-args="post,10,10,<?php echo um_user('ID'); ?>"><?php _e('load more posts','ultimatemember'); ?></a>

Where it says post,10,10 change post to the post type that you would like for example um_story,10,10

 <a href="#" class="um-ajax-paginate um-button" data-hook="um_load_posts" data-args="um_story,10,10,<?php echo um_user('ID'); ?>"><?php _e('load more posts','ultimatemember'); ?></a>

Save the file and there you have it. If you have followed the steps as mentioned here, you should now have a list of another post type.

We use this feature in our plugin Stories for Ultimate Member.

Happy Coding!

Do you need help with your WordPress site?

Check out our WordPress Services and get the help fast.