0

I wrote this code:

<?php
$category_border_color = get_field('category_border_color');
$image = get_field('main_image');
$short_description = get_field('short_description');
$permalink = get_permalink('custom_link');
$more_link_text = get_field('more_link_text');
$event_date_from = get_field('event_date_from');

?>
<?php if ($event_date_from) : ?>
    <div class="col-md-6 post-item">
        <a href="<?php get_the_permalink(); ?>">
            <div class="image-wrap" style="background-image: url(<?php echo $image['sizes']['medium']; ?>);"></div>
            <div class="category_name" style="border-color: <?php echo $category_border_color  ?>"><?php the_title(); ?></div>
        </a>
        <div class="short_text">

            <?php echo $short_description  ?> – <span class="more-link"><a href="<?php get_the_permalink(); ?>"><?php echo $more_link_text  ?></a></span>
        </div>
    </div>
<?php endif; ?>

But the href link isn´t working, in sitecode in frontend it shows: <a href="">Mehr Infos!</a>

So for some reason it doesn´t work the connection to the permalink.
Can someone help please?

Best regards,
Caro

1 Answer 1

1

get_the_permalink() returns the permalink as a string and doesn't echo it. You either need to echo this yourself

<?php echo get_the_permalink(); ?>

as you've got in some of your other <?php tags, or you can use the helper function the_permalink() which does echo

<?php the_permalink(); ?>

the same pattern as you've used for the_title().

Note that these aren't completely equivalent: the_permalink() applies an extra filter, so it's probably worth using that one in case some other code you've got does use the filter.

4
  • 1
    So I don't think there's anything ACF here after all. Note also that you're generating a link $permalink and not using that - what's that for? Do you still need it?
    – Rup
    Commented Aug 14 at 7:41
  • Yo got it! It works! Thank you a lot for your help :D
    – Caro
    Commented Aug 14 at 9:16
  • 1
    Just to add to this: the above is a common pattern in WP function names. get_something() will return something, the_something() will echo it.
    – Chris Cox
    Commented Aug 14 at 10:45
  • Thank you too for this important information
    – Caro
    Commented Aug 14 at 13:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.