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 -->   
  • 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 Aug 4 '17 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 Aug 4 '17 at 15:25
  • WebElaine:- No, I am only using ACF PRO and I only have ACF fields. – Jon_Snow Aug 4 '17 at 15:27
  • Jacob: The search results are not showing the ACF Custom Post content. They are showing everything else. – Jon_Snow Aug 4 '17 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 Aug 4 '17 at 15:29
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 -->   
  • It worked but partially. It is now showing the full content of all the pages. For example:- I have 4 sections on the Artist page all under different divs 1. Name 2. Description 3. Similar Artist 4. Videos Since the similar artist section has names of all the artists, the search results are always showing all the pages and content in the search result. How can I limit the results to just one subfield "Description" – Jon_Snow Aug 4 '17 at 15:45
  • That means, if that word is in description subfield it should only show the content of the description in the search results. So, no read more button. All the content on the search page but for the particular subfields only. – Jon_Snow Aug 4 '17 at 15:46
  • Something like the search of advancedcustomfields.com/resources Only searches for the divs containing the searched keyword. – Jon_Snow Aug 4 '17 at 15:51
  • WordPress search doesn't search the contents of custom fields. That's a whole other issue. Your specific question was about including fields in the results template. – Jacob Peattie Aug 4 '17 at 16:31
  • It worked like a charm after a little more effort. Thank you for your help. You did resolved most part of the problem – Jon_Snow Aug 9 '17 at 16:20

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.