Hi @mantachris
Please try adding this code snippet to your theme/child-theme’s functions.php file or use the Code Snippet plugin to run the code:
function um_custom_data_restricted_singular_post( $post, $restriction_settings, $original_post ) {
// if you want to show the original post title instead of the restriction content title
// use these object keys https://developer.wordpress.org/reference/functions/get_post/#comment-876
$post->post_title = $original_post->post_title;
// sometimes $original_post is already customized then please use this way
$p = get_post( $original_post->ID );
$post->post_title = $p->post_title;
// please use this line if you need to restore the post excerpt
$post->post_excerpt = $p->post_excerpt;
return $post;
}
add_filter( 'um_restricted_singular_post', 'um_custom_data_restricted_singular_post', 10, 3 );
The above code will show the post excerpt for restricted post.
Regards,
Hi @champsupertramp, thanks for your reply and help!
Sorry for asking maybe too much (codes and coding is not my strength) but could you show me an example on how I can implement the code for a specific post via the Code Snippet Plugin?
How am I supposed to define the variables for a specific post to make it work?
Thanks.
Best,
-
This reply was modified 2 years, 5 months ago by mantachris.
Hi @mantachris
You can try the following code snippet. Just change the ID 123
to your post ID.
function um_custom_data_restricted_singular_post( $post, $restriction_settings, $original_post ) {
if( $original_post->ID == 123 ){
// if you want to show the original post title instead of the restriction content title
// use these object keys https://developer.wordpress.org/reference/functions/get_post/#comment-876
$post->post_title = $original_post->post_title;
// sometimes $original_post is already customized then please use this way
$p = get_post( $original_post->ID );
$post->post_title = $p->post_title;
// please use this line if you need to restore the post excerpt
$post->post_excerpt = $p->post_excerpt;
}
return $post;
}
add_filter( 'um_restricted_singular_post', 'um_custom_data_restricted_singular_post', 10, 3 );
Regards,
Hi @champsupertramp, thanks for the help. Sadly, changing the ID to one of my post IDs didn’t work when using the code snippets plugin.
I believe that the ultimate layouts filter plugin is conflicting with ultimate member or preventing running the code.
Interestingly, I found out that when I change the global site access in ultimate member to logged in useres only and exclude only the page in question, it shows the previews of all posts but still keeps them restricted.
That would be an option but I still would need to add every single URL from the rest of my site to be excluded by the restriction…
Do you maybe have any other idea on how to work around this or would you just recommend trying it this way?
BR and thanks again for the help,
mantachris
Hi @mantachris
Does the code without the post ID work? Does it show the excerpt and post title?
Regards,
Hi @champsupertramp, sadly not. Here’s is how I copied both codes into the code snippet plugin, maybe I did something wrong:
without ID: https://paste.pics/8f8f9574e2b128809d53c57a9a268939
with ID: https://paste.pics/3881e8e8315ec5c959016756d933451f
Restriction settings at post /wp-admin/post.php?post=8833&action=edit&lang=en: https://paste.pics/1a20c8eaefae14f78de9e341814add2f
The outcome is still the same as in the first picture I shared at the beginning of this thread.
BR,
mantachris
Hi @mantachris
Could you please try adding this code along with the previous code provided above?
add_filter( 'um_ignore_restricted_title', '__return_true' );
add_filter( 'um_ignore_restricted_excerpt', '__return_true' );
add_filter( 'um_ignore_restricted_content', '__return_true' );
Regards,
Hi @champsupertramp, works like a charm!
Only thing that’s left, if it’s possible, is there anyway to also show the post thumbnail?
Currently it looks like this: https://paste.pics/7f85d907b104303f14ce1c12946d4f7e
I tried to add these codes:
$post->post_thumbnail = $p->post_thumbnail;
and add_filter( 'um_ignore_restricted_thumbnail', '__return_true' );
I also tried the line add_filter( 'um_ignore_restricted_post_thumbnail', '__return_true' );
Both did not work…
Do you have any idea how to also restore the post thumbnail / featured image?
THANKS!
BR,
mantachris
-
This reply was modified 2 years, 5 months ago by mantachris.
-
This reply was modified 2 years, 5 months ago by mantachris.
Hi @mantachris
For the thumbnail/featured image, you can try the following:
add_filter("um_restrict_post_thumbnail","__return_true");
Regards,
@champsupertramp perfect, thanks so much for the help!!!
Have a nice day 🙂
Thanks for letting us know.
Regards,