
By default, in the Ultimate Member profile page at the posts tab, it only shows the “post” post_type of a user.
This is the page I am talking about:
https://rynerworld.com/user/ryner/?profiletab=posts.
It doesn’t really show the posts of custom post types. So here is a quick fix for that.
Simple Code
<?php
// create your function
function custom_um_profile_query_make_posts( $args = array() )
{
$args['post_type'] = 'custom_post_type';
return $args;
}
// call your function using the UM hook
add_filter( 'um_profile_query_make_posts', 'custom_um_profile_query_make_posts', 12, 1 );
?>
This is the ultimate churvaness to change the posts displayed at the profile page.
Reminder tho, with this code, we have overridden the post type that is shown, meaning, the posts with the “post” post_type will not be shown.
So to fix this, we pass an array.
<?php
// create your function
function custom_um_profile_query_make_posts( $args = array() )
{
$args['post_type'] = ['post','custom_post_type'];
return $args;
}
// call your function using the UM hook
add_filter( 'um_profile_query_make_posts', 'custom_um_profile_query_make_posts', 12, 1 );
?>
There you go! Now we are showing both post types. This can also be used for more post types.
Code inside a class
If you are working inside a class, you simply need to add one word lol.
<?php
if( ! class_exists('RYNERWORLD') ) :
class RYNERWORLD
{
function __construct() {
add_filter( 'um_profile_query_make_posts', [$this, 'custom_um_profile_query_make_posts'], 12, 1 );
}
function custom_um_profile_query_make_posts( $args = array() ) {
$args['post_type'] = ['post','custom_post_type'];
return $args;
}
}
new RYNERWORLD();
endif;
?>
Proof?
For proof that it actually works, visit this one:
https://rynerworld.com/user/diannemae/?profiletab=posts
The posts for this user have “entry” post_type. That’s the proof lol.
Additionals
For more information, you can visit the Ultimate Member Documentation regarding this. Though it really does lack information. hahaha
Cheers!
If you have any questions, comment below.
And if you think this is kinda helpful, share it with your friends? hihihi
Happy coding!
0 Comments