So I'm running into issues retrieving the get_author_posts_url()
- I'm still in the learning process and want to know why this might be happening:
Here is the code:
<!-- Locate the header.php file under /templates/ -->
<?php include(locate_template('templates/header.php')); ?>
<!-- This is the posts loop, grabs the permalink, the title attributes and the title -->
<?php if (have_posts()) { ?>
<?php while (have_posts()) { ?>
<?php the_post(); ?>
<h2>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title() ?></a>
</h2>
<div>
Posted on
<a href="<?php echo get_permalink(); ?>">
<!-- Grab the date: .date.php -->
<time datetime="<?php echo get_the_date('c') ?>" itemprop="datePublished"><?php echo the_date(); ?></time>
</a>
By <a href="<?php get_author_posts_url(get_the_author_meta('ID')) ?>"><?php echo get_the_author(); ?></a>
</div>
<?php } ?>
<?php } else { ?>
<p>Sorry, no posts match your criteria.</p>
<?php } ?>
<!-- Locate the footer.php file under /templates/ -->
<?php include(locate_template('templates/footer.php')); ?>
This is the result:
So I'm running into issues retrieving the get_author_posts_url()
- I'm still in the learning process and want to know why this might be happening:
Here is the code:
<!-- Locate the header.php file under /templates/ -->
<?php include(locate_template('templates/header.php')); ?>
<!-- This is the posts loop, grabs the permalink, the title attributes and the title -->
<?php if (have_posts()) { ?>
<?php while (have_posts()) { ?>
<?php the_post(); ?>
<h2>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title() ?></a>
</h2>
<div>
Posted on
<a href="<?php echo get_permalink(); ?>">
<!-- Grab the date: https://www.php/manual/en/function.date.php -->
<time datetime="<?php echo get_the_date('c') ?>" itemprop="datePublished"><?php echo the_date(); ?></time>
</a>
By <a href="<?php get_author_posts_url(get_the_author_meta('ID')) ?>"><?php echo get_the_author(); ?></a>
</div>
<?php } ?>
<?php } else { ?>
<p>Sorry, no posts match your criteria.</p>
<?php } ?>
<!-- Locate the footer.php file under /templates/ -->
<?php include(locate_template('templates/footer.php')); ?>
This is the result:
- Are you sure that code is what generated that result? There is a " in between </a> and By that isn't in the code, so it seems like maybe you fixed/corrected something? – mozboz Commented Jun 27, 2020 at 11:59
- @mozboz, looks like I forgot a echo facepalm – Swe Commented Jun 27, 2020 at 12:01
- hah, well spotted, i was looking and didn't notice :D – mozboz Commented Jun 27, 2020 at 12:03
1 Answer
Reset to default 0Adding answer for reference:
get_author_posts_url(get_the_author_meta('ID'))
retrieves the value into the PHP code, it doesn't automatically output it, so you need:
echo get_author_posts_url(get_the_author_meta('ID'));
To output it into the HTML