Simple Membership Plugin › Forums › Simple Membership Plugin › Post Custom Field – Post Prtection
Tagged: custom field, protection
- This topic has 8 replies, 2 voices, and was last updated 4 years, 5 months ago by
Martin.
-
AuthorPosts
-
January 19, 2022 at 4:21 pm #23491
Martin
ParticipantHello! Congratulations for the great plug in
I am using it since more than 3 years and it is working very well for me.Now I am trying to show in my post list if a post is protected or if it is free for all
So I am looking in the post custom fields hoping to find a field that says if the post is protected or not.Is there this field?
Can you please help me finding it?Thanks
January 20, 2022 at 7:57 am #23494Eldon McGuinness
ParticipantYou could go the route of a shortcode:
function swpm_is_protected() { $protected = SwpmProtection::get_instance(); return ( $protected->is_protected( get_the_ID() ) == true ) ? 'Protected' : 'Public'; } function swpm_shortcode_init(){ add_shortcode( 'swpm_protected', 'swpm_is_protected' ); } add_action('init', 'swpm_shortcode_init');Then just use [swpm_protected] in your posts. Of course, you would want to format it and what not, but this would work.
January 20, 2022 at 12:54 pm #23496Martin
ParticipantThank you for your help. I will try to use your code. Since I am not a coder I will have to find some help.
January 20, 2022 at 4:37 pm #23497Eldon McGuinness
ParticipantPut it at the end or your functions.php file and then you can just use [swpm_protected] in your posts and pages. If you’re looking for something more specific let me know.
January 20, 2022 at 6:19 pm #23498Martin
ParticipantVery kind of you to help me!
I am grateful 🙂I tried to add at the end of functions.php but I get an error:
Sintax error, unexpected $E0F
I have pasted this code:
/** *swpm post protection custom field */ function swpm_is_protected() { $protected = SwpmProtection::get_instance(); return ( $protected->is_protected( get_the_ID() ) == true ) ? 'Contenido Exclusivo Certificados FdB' : 'Contenido Libre'; } function swpm_shortcode_init(){ add_shortcode( 'swpm_protected', 'swpm_is_protected' ); } add_action('init', 'swpm_shortcode_init')January 21, 2022 at 7:09 pm #23504Eldon McGuinness
Participant/** *swpm post protection custom field */ function swpm_is_protected() { $protected = SwpmProtection::get_instance(); return ( $protected->is_protected( get_the_ID() ) == true ) ? 'Contenido Exclusivo Certificados FdB' : 'Contenido Libre'; } function swpm_shortcode_init(){ add_shortcode( 'swpm_protected', 'swpm_is_protected' ); } add_action('init', 'swpm_shortcode_init');The last line was missing a ‘;’
January 21, 2022 at 10:27 pm #23506Martin
ParticipantThis worked, thanks so much! 🙂
Now when I use [swpm_protected] I get as an output like this:
“{{ post_meta_value: Contenido Exclusivo Certificados FdB }}”
I would like to have only the tex pat like this:
“Contenido Exclusivo Certificados FdB”
is there a simple way to achieve it?
January 22, 2022 at 3:59 am #23508Eldon McGuinness
ParticipantI’m not seeing that, instead, I’m seeing exactly what you said you wanted.
January 22, 2022 at 11:19 am #23514Martin
ParticipantOk I solved that.
It was because I am putting the shortcode inside wp bakery… Thanks you very much for your help, really appreciated. -
AuthorPosts
- You must be logged in to reply to this topic.