• Resolved Angie Meeker

    (@ameeker)


    When writing conditional statement that includes has_tag, do you have to include the custom post type if the taxonomy’s attached to it only? So… if the CPT is x, and has tag Y, and is single, then… OR, just is single and has tag?

    if ( !is_single() || has_tag( 'tours')  )
    		return;

    Should that return what follows it on single pages with the tag tours? (it’s not, and I tried has_term, too).

Viewing 3 replies - 16 through 18 (of 18 total)
  • which won’t work. To use multiples it needs to be an array
    has_term ( array('tours', 'attractiontype') )

    No the function gives 3 parameters:

    <?php has_term( $term, $taxonomy, $post ) ?>

    I think attractiontype is the taxonomy, not another term.

    @ameeker : Can’t you just use ACF to create your own condition?

    1. In ACF, create a checkbox field, “Display Special Box on the Site”.
    2. All the other fields have the condition to only display in the post editor if “Display Special Box” is checked..or not if you want them to always show.
    3. Furthermore, in single-attraction.php try something like:

    <?php if ( get_field('use_special_box')): //Conditional Check ?>
    
        <div> <?php the_field('whatever'); // Display Field if true?> </div>
    
    <?php endif; ?>

    Thread Starter Angie Meeker

    (@ameeker)

    @christian1012 – I see what you’re saying and that seems like a feasible workaround… but it’s not the right solution. I need the “tours” to be created through the taxonomy, not ONLY as a set of custom fields.

    The thing is this – what I’m building in is a fail-safe of sorts… because IF the user doesn’t enter any info into the custom fields for Tour Information, of course, no info will show that post anyway ((except the TOUR INFORMATION headline which I still need to move so it doesn’t show unless there is tour info)).

    I’d like them to HAVE to mark the attraction as a tour in order for the Tour Information they enter to show up, so that the attraction then shows in the Tours archive, not just with Tour Information included in its post in Attractions. I could see a scenario where the user enters tour information, but doesn’t tag the post Tours, then wonders why Tour didn’t show in the Tours archive. I’m trying to prevent that.

    Thread Starter Angie Meeker

    (@ameeker)

    So I went with @christian1012’s thought to use a checkbox to conditionally display the metabox fields for the tour info in the first place on the Attraction posts. Then, this paste https://pastebin.com/RRjrz3a4 worked to display the Tour Information only on the single posts with some tour information filled out. The user will still have to tag the post “tour” but that only makes sense.

    Thanks everyone!

Viewing 3 replies - 16 through 18 (of 18 total)
  • The topic ‘Conditional statement, CPT, single, with tag’ is closed to new replies.