程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了从 ACF 关系字段获取永久链接大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决从 ACF 关系字段获取永久链接?

开发过程中遇到从 ACF 关系字段获取永久链接的问题如何解决?下面主要结合日常开发的经验,给出你关于从 ACF 关系字段获取永久链接的解决方法建议,希望对你解决从 ACF 关系字段获取永久链接有所启发或帮助;

我有一个名为“作者”的 CPT。在默认帖子中,我使用 ACF 关系字段指定其中一位作者。

我使用 ALM 插件(客户的请求)创建了一个循环来显示所有博客文章。对于每篇博文,我都希望包含作者姓名和相应的单个作者页面的永久链接。这可能吗?

我试图按照 this post 上的 single-doctor.php 示例进行操作,但它不起作用。我怀疑这是因为我的关系字段在帖子上而不是作者 CPT(或者使用这个例子,在位置而不是医生)。

<div class="posts-grID">
        <?php
        /*
         *  query posts for a relationship value.
         *  This method uses the Meta_query liKE to match the String "123" to the database value a:1:{i:0;s:3:"123";} (serialized array)
         */

         $blogs = get_posts(array(
            'post_type' => 'post','posts_per_page' => '12','Meta_query' => array(
            array(
              'key' => 'post_author',// name of custom fIEld
              'value' => '"' . get_the_ID() . '"',// matches exactly "123",not just 123. This prevents a match for "1234"
              'compare' => 'liKE'
                )
            )
          ));
            ?>
          <?php if( $blogs ): ?>
          <?php foreach( $blogs as $blog ): ?>
          <div class="post-item">
                        <a href="<?php echo get_permalink($blog->ID); ?>">
                            <div class="bg-image" style="BACkground-image: url('<?php echo get_the_post_thumbnail_url($blog->ID,'large');?>')">
                            </div>
                        </a>
                        <div class="content">
                <a href="<?php echo get_permalink($blog->ID); ?>">
                <h3><?php echo get_the_title($blog->ID); ?></h3>
                </a>
                            <p><?php echo get_the_time('F j,Y',$blog->ID);?></p>
                            <p><?php echo get_the_excerpt($blog->ID);?></p>
                            <a href="<?php echo get_permalink($blog->ID); ?>">Read Post</a>
                        </div>
          </div>
          <?php endforeach; ?>
          <?php endif; ?>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

大佬总结

以上是大佬教程为你收集整理的从 ACF 关系字段获取永久链接全部内容,希望文章能够帮你解决从 ACF 关系字段获取永久链接所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: