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
版权声明:本文标题:customization - Advanced Custom Fields in WP_Query: Href Returning Empty 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736304761a1932345.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论