最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - ACF Post Content Not Being Searched

programmeradmin1浏览0评论

I don't seem to understand. All the other post type data is being searched by the default wordpress search but when I try to search the Custom Post type data, it just gives me the page title and not the content. What is this issue.

Here is my search.php code

  <div class="contentarea">
  <div id="content" class="content_right">      
   <?php if ( have_posts() ) :
        while ( have_posts() ) : the_post(); ?>    
        <div id="post-<?php the_ID(); ?>" class="posts">
        <article>        
            <h4><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h4>        
        <p><?php the_content();?></p>        
        <a href="<?php the_permalink();?>">Read More</a>
        </article>
    </div>
    <?php endwhile; ?>
    <?php endif; ?>
   </div><!-- content -->    
   </div><!-- contentarea -->   

I don't seem to understand. All the other post type data is being searched by the default wordpress search but when I try to search the Custom Post type data, it just gives me the page title and not the content. What is this issue.

Here is my search.php code

  <div class="contentarea">
  <div id="content" class="content_right">      
   <?php if ( have_posts() ) :
        while ( have_posts() ) : the_post(); ?>    
        <div id="post-<?php the_ID(); ?>" class="posts">
        <article>        
            <h4><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h4>        
        <p><?php the_content();?></p>        
        <a href="<?php the_permalink();?>">Read More</a>
        </article>
    </div>
    <?php endwhile; ?>
    <?php endif; ?>
   </div><!-- content -->    
   </div><!-- contentarea -->   
Share Improve this question asked Aug 4, 2017 at 15:21 Jon_SnowJon_Snow 183 bronze badges 5
  • To clarify - it sounds like you are using Advanced Custom Fields along with a Custom Post Type. Do you have a regular content editor in your CPT? Or, do you only have ACF fields? If you only have ACF fields and no default content editor, then WordPress is seeing "no content" because you have no content in its built-in editor. You would need to add a conditional in search.php so that if the post type equals your CPT, you would display the ACF fields' content instead of the_content(). – WebElaine Commented Aug 4, 2017 at 15:25
  • I'm unclear on the question. Are you saying that the content doesn't appear in search results, or that it's not finding search terms in the content? – Jacob Peattie Commented Aug 4, 2017 at 15:25
  • WebElaine:- No, I am only using ACF PRO and I only have ACF fields. – Jon_Snow Commented Aug 4, 2017 at 15:27
  • Jacob: The search results are not showing the ACF Custom Post content. They are showing everything else. – Jon_Snow Commented Aug 4, 2017 at 15:28
  • WebElaine:- How and where should I add the conditional statement in the code above. My ACF Custom post type is "Artist" and has a repeater field "Details" which contains 2 subfields "Name" "Description" – Jon_Snow Commented Aug 4, 2017 at 15:29
Add a comment  | 

1 Answer 1

Reset to default 0

Advanced Custom Fields does not automatically output the fields you add in the_content(). You need to use ACF's template functions. Refer to the documentation for more.

Based on your comment, yours will look something like:

<div class="contentarea">
    <div id="content" class="content_right">
        <?php if ( have_posts() ) :
            while ( have_posts() ) : the_post(); ?>
                <div id="post-<?php the_ID(); ?>" class="posts">
                    <article>
                        <h4><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h4>        
                        <p><?php the_content();?></p>

                        <?php while ( have_rows( 'details' ) ) : the_row(); ?>
                            <?php the_sub_field( 'name' ); ?><br>
                            <?php the_sub_field( 'description' ); ?>
                        <?php endwhile; ?>

                        <a href="<?php the_permalink();?>">Read More</a>
                    </article>
                </div>
            <?php endwhile; ?>
        <?php endif; ?>
    </div><!-- content -->    
</div><!-- contentarea -->   
发布评论

评论列表(0)

  1. 暂无评论