My first Shortcode ---

HI guys I’m trying to write a simple shortcode that hides some content from a buddypress member type.
BUT the info appears in a user post, so we want to hide the item IF the post author is that member type.
The plugins available hide the content if the logged in user is the member type, I need to hide the content if the post author has a particular post type.

And, every wanting to learn and get better at PHP.
This is a hard one for me, hope I did it not to far off.

/**

  • Hide content from Casting Buyers
    */

function hide_from_casting_function( $atts, $content = null ) {
// fetch post author id
$user_id = get_the_author_meta(‘ID’);
// Get the member type of user the author.
$member_type = bp_get_member_type( $user_id );
// if casting_buyer hide from front end.
if ( ‘casting_buyer_type’ != $member_type )
{return ‘’ . $content . ‘’;}
}
add_shortcode(‘hide_from_casting’, ‘hide_from_casting_function’);

What’s the question? If you’re seeing an error, can you include it?

Hi
Sorry thanks for responding! I’m grateful for the response.

Its not hiding the content I put inside the shortcode.

  • I’ve defined the buddypress member type which is casting_buyer_type,
  • and I want to get the member type of the post author.
  • Then if that post author is a casting_buyer_type
  • I want to hide the content inside the shortcode.

It’s not hiding the content,
I"m wondering if my syntax is correct php wise.

Also the users only see the box if they are logged in.
This is the first php I’ve tried to write by hand, and I’m putting it in the bp-custom.php
does it need to go in the main functions.php?

Is it enough to just add_shortcode and then it should work in the wordpress post,
or do you need to also tell it to do shourcode

OMG I think its because I have != in the if statement!! omg.
I’ll see if that fixes it.
Sorry this is a new language, and I’m persevering.

Sponsor our Newsletter | Privacy Policy | Terms of Service