problem with get_author_posts_url
-
Hi! I’m running into this problem with a custom page I’ve set up to list authors according to a custom field (using Advanced Custom Fields).
Even though the query works fine (that is, the results are those I’m expecting), I simply can’t get the URL for the author archive page to work. Here’s my code:<?php /** * Template Name: Authors list * @package Educaz */ get_header(); ?> <div id="primary" class="content-area grid__col grid__col--2-of-3"> <main id="main" class="site-main" role="main"> <?php // wp_user_query arguments $argsProf =array( 'order' => 'ASC', 'orderby' => 'ID', 'meta_key' => 'academic_level', 'meta_value' => 'professor' ); //create wp_user_query object $queryProf = new wp_user_query($argsProf); //get the results $professors = $queryProf->get_results(); //check for professors if (! empty($professors)) { echo '<ul>'; foreach ($professors as $professor) { $professor_info = get_userdata($professor->ID); echo '<li><a href="' . <strong>esc_url(get_author_posts_url($professor_info->ID, $professor_info->user_nicename))</strong> . '">' . $professor_info->display_name . '</a></li>'; } echo '</ul>'; } ?> </main><!-- #main --> </div><!-- #primary --> <?php get_sidebar(); get_footer();
The code works fine if don’t call get_header, but then, of course, the theme doesn’t load properly on the page.
Two things I’ve tried also didn’t work:
1. Someone suggested I shouldn’t do a wp_user_query using custom fields as meta_key. I then changed the query to a simpler one, using ‘search’ as a parameter. No luck. (Again, the query in the code above seems to work fine, since it retrieves the results I’m expecting)
2. I’ve also tried hardcoding an ID in get_author_posts_url. That also doesn’t work, surprisingly. I’ve even tried echoing the get_author_posts_url, but I get nothing.
- The topic ‘problem with get_author_posts_url’ is closed to new replies.