admin管理员组

文章数量:1122846

I'm still learning the ropes of PHP so please bear with me!

So basically I have an ACF URL field "author_link" that I want to generate on a "table of contents" page in a list format along with another ACF text field "author_name" .

The author name is displaying fine in the list (when I put get_field directly in the echo), but I cannot seem to get the author link to display in the "href".

Both the author name and author link fields are populated in the posts and are in the same field group in ACF. I also confirmed that the field names are correct and do have values entered.

Here is my code:

<div class="block wrapper">
<h2><span>Contributing Authors</span></h2>
    
<ul>
    <?php 
    $author_name = get_field ('author_name') ;
    $author_link = get_field( 'author_link' );
    $args = array (
    'post_type' => 'post', // your post type
    'posts_per_page' => -1, // grab all the posts
    'meta_key' => 'author_name', 
    'meta_compare' => 'EXISTS', // make sure the post have this acf value
    'orderby'           => 'meta_value',
    'order'   => 'ASC',
    );
    
$query = new WP_Query($args);
    
while ($query->have_posts()): $query->the_post();
    echo '<li>';
    echo '<a href="' . $author_link . '">';
    echo get_field ('author_name') ;
    echo '</a>';
    echo '</li>';

endwhile;
    

wp_reset_query();

    
    ?>
    
    </ul>   

</div>

Additionally, I would like the list results to sort in ASC alphabetical order by the last name of the author. Is there any way I can incorporate usort into this code?

Your help is much appreciated!

本文标签: customizationAdvanced Custom Fields in WPQuery Href Returning Empty