Support

Account

Home Forums General Issues Hide Content with radio button

Solving

Hide Content with radio button

  • Hello to everyone I added a radio button custom field called “vedi_autore” where values are “yes/no” https://ibb.co/C0GkYh0

    If “yes(si)”, author post must be displayed into slider: https://ibb.co/4Pkw95d

    If “no”, author post must be hidden https://ibb.co/6tDcynB (Maurizio Eufemi author is hidden)

    In order to do this i write the following code into post_author.php

    if(get_field('vedi_autore') == 'si') { 
    
    Output Post Author element
    
    }

    This code works correctly and the author will be hidden based on condition: https://ibb.co/pXQNPH6

    but also here in homepage: https://ibb.co/xXQd8JB

    I need that code will be applied only for slider post. I tried a solution with CSS since there is a custom class but not works.

    However in the end my final purpose is that i can choose to display or not author name in slider.

    Thanks for any suggestion

  • You need to check the post type of the post being displayed
    This is just an example, untested code, it will probably need to be altered based on your needs. For example, I don’t even know if get_post_type() will work here

    
    if (get_post_type() != 'slider-post-type' || get_field('vedi_autore') == 'si') {
     Output Post Author element
    }
    
  • Ok i think your suggestion should work.

    1) This is visual composer: https://ibb.co/JBmv1DH as you can see i have layout grid 8967

    2) If i go to edit that section: https://ibb.co/Rpqx5c4 in url i can see /post.php?post=8967&action=edit

    3) In inspector i can see the tag layout_8967 as class: https://ibb.co/RT0cg4J

    So the code should like this?

    if (get_post_type() == 'layout_8967' && get_field('vedi_autore') == 'si') {
     Output Post Author element
    }
Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.