• How can i only show content by user id.

    I need an if statement something like,

    if user id is 5 then do this, else, do this?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator Bet Hannon

    (@bethannon1)

    Can you be more specific about what kind of content (posts, pages, custom post type)? Sharing a site url might really help too.

    Are you wanting to filter and only show posts with a certain tag or category to particular users? How individual/granular will this need to be– will you have 3 categories of users that you need to show different content to? Or, do you need to have each user have a unique content pulled?

    Thread Starter dannyblank

    (@dannyblank)

    What we want to do is literally show or hide custom fields within woocommerce post types by user id.

    We do not need to use roles such as subscriber etc, this would need to be purely on a per user basis.

    Ideally something such as:

    <?php if ($current_user->user_login == '5') { ?>
    <div id="miffy">Quantity<br/><?php echo get_editable_post_meta( get_the_ID(), 'quantitiy', 'input', true ); ?></div>
    <?php } else { ?>
    <div id="miffy">Size<br/><?php echo get_editable_post_meta( get_the_ID(), 'size', 'input', true ); ?></div>
    <?php } ?>

    Thank you very much for your reply, really appreciated!

    Something like this?

    $customer_id = get_current_uer_id();
    
    if( $customer_id == 5 ){
        echo "<p>First customer</p>";
    }
    else{
       echo "<p>Default text.</p>";
    }
    Thread Starter dannyblank

    (@dannyblank)

    Thanks catacaustic

    Its very close,

    i just tried this and it works!

    <?php
    $customer_id = get_current_user_id();
    
    if( $customer_id == 1 ){ ?>
        <div id="miffy">Company1<br/><?php the_author_meta( 'nickname', $userID ); ?></div>
    <div id="miffy">Quantity1<br/><?php echo get_editable_post_meta( get_the_ID(), 'ebbage', 'input', true ); ?></div>
    <div id="miffy">Grade1<br/><?php echo get_editable_post_meta( get_the_ID(), 'radio', 'input', true ); ?></div>
    <div id="miffy">Price1<br/>&pound;<?php echo get_editable_post_meta( get_the_ID(), 'mark', 'input', true ); ?></div>
      <?php
    
    } else {
       echo "<p>Default text.</p>";
    }
    ?>

    However, i want the else to also allow php so i need to remove the second part echo "<p>Default text.</p>";

    So it looks something like this;

    <?php
    $customer_id = get_current_user_id();
    
    if( $customer_id == 1 ){ ?>
        <div id="miffy">Company1<br/><?php the_author_meta( 'nickname', $userID ); ?></div>
    <div id="miffy">Quantity1<br/><?php echo get_editable_post_meta( get_the_ID(), 'ebbage', 'input', true ); ?></div>
    <div id="miffy">Grade1<br/><?php echo get_editable_post_meta( get_the_ID(), 'radio', 'input', true ); ?></div>
    <div id="miffy">Price1<br/>&pound;<?php echo get_editable_post_meta( get_the_ID(), 'mark', 'input', true ); ?></div>
      <?php
    
    } else {
    <div id="miffy">Company<br/><?php the_author_meta( 'nickname', $userID ); ?></div>
    <div id="miffy">Quantity<br/><?php echo get_post_meta( get_the_ID(), 'ebbage', 'input', true ); ?></div>
    <div id="miffy">Grade<br/><?php echo get_post_meta( get_the_ID(), 'radio', 'input', true ); ?></div>
    <div id="miffy">Price<br/>&pound;<?php echo get_post_meta( get_the_ID(), 'mark', 'input', true ); ?></div>
    }
    ?>
    Thread Starter dannyblank

    (@dannyblank)

    I worked it out ??

    <?php
    $customer_id = get_current_user_id();
    
    if( $customer_id == 1 ){ ?>
        <div id="miffy">Company<br/><?php /* the_author_meta( 'nickname', $userID ); */?>001</div>
        <div id="miffy">Manufacturer<br/><?php /* the_author_meta( 'nickname', $userID ); */?>Apple</div>
        <div id="miffy">OEM Code<br/><?php /* the_author_meta( 'nickname', $userID ); */?>M1960G/A</div>
    <div id="miffy">Grade A Quantity<br/><?php echo get_editable_post_meta( get_the_ID(), 'ebbage', 'input', true ); ?></div>
    <div id="miffy">Grade B Quantity<br/><?php echo get_editable_post_meta( get_the_ID(), 'radio', 'input', true ); ?></div>
    <div id="miffy">Grade C Quantity<br/>&pound;<?php echo get_editable_post_meta( get_the_ID(), 'mark', 'input', true ); ?></div>
    <div style="height: 10px; clear: both;"></div>
    <?php } else { ?>
        <div id="miffy">Company<br/><?php /* the_author_meta( 'nickname', $userID ); */?>001</div>
        <div id="miffy">Manufacturer<br/><?php /* the_author_meta( 'nickname', $userID ); */?>Apple</div>
        <div id="miffy">OEM Code<br/><?php /* the_author_meta( 'nickname', $userID ); */?>M1960G/A</div><div id="miffy">Quantity<br/><?php echo get_post_meta( get_the_ID(), 'ebbage', 'input', true ); ?></div>
    <div id="miffy">Grade<br/><?php echo get_post_meta( get_the_ID(), 'radio', 'input', true ); ?></div>
    <div id="miffy">Price<br/>&pound;<?php echo get_post_meta( get_the_ID(), 'mark', 'input', true ); ?></div>
    <div style="height: 10px; clear: both;"></div>
    <?php } ?>
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to show content by user is?’ is closed to new replies.