WPFTS Pro Main Site WPFTS Community Forum
    • Recent
    • Tags
    • Popular
    • Register
    • Login
    Get WPFTS Pro today with 25% discount!

    [Solved] Show Smart Excerpt for attachments with WP_Query()?

    Scheduled Pinned Locked Moved Recipes and Known Solutions
    smart excerptwpquery
    3 Posts 2 Posters 907 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • EpsilonAdminE
      EpsilonAdmin
      last edited by EpsilonAdmin

      Sometimes it can be a problem to show the content of the attachment file in search results using the Smart Excerpt way.

      Conor Campbell asked:

      One of my clients utilizes your WordPress plugin to index documents on their site.

      It works great, however, I am unable to get excerpts to appear for
      PDFs, as they're using a custom search results page. What
      information do you require from me in order to investigate this?

      Looking forward to your response.

      Yes, the Smart Excerpt function is only activated automatically when you
      are making WP Main Search. In case you want to force Smart Excerpts for
      custom WP_Query() request, you need to do this:

      global $wpfts_core;
      
      $result = new WP_Query(array(
           's' => $string_query,  // A search string which you're searching for
          ...other your parameters to filter results...
      ));
      
      // This will enable Smart Excerpts
      $wpfts_core->ForceSmartExcerpts($string_query);
      
      // Here is your code to loop over $result to view search results
      // You need to use the_excerpt(); to show Smart Excerpts
      
      // Check that we have query results.
      if ( $query->have_posts() ) {
      
          // Start looping over the query results.
          while ( $query->have_posts() ) {
       
              $query->the_post();
       
              // Contents of the queried post results go here.
              // the_title();
              // the_excerpt();
              //....
          }
       
      }
       
      // Restore original post data.
      wp_reset_postdata();
      
      // You may disable Smart Excerpts if you need to (OPTIONAL)
      $wpfts_core->ForceSmartExcerpts(false);
      

      Hope this helps.

      https://e-wm.org

      C 1 Reply Last reply Reply Quote 0
      • C
        conor @EpsilonAdmin
        last edited by

        @EpsilonAdmin Thank you, that does help.

        Is it possible to display the PDF content as the excerpt of a post it is embedded in though?

        For example: "Sample Post" has no content except for an embedded PDF. I would like some text from that PDF to display in the search results, but the permalink goes to "Sample Post".

        1 Reply Last reply Reply Quote 0
        • EpsilonAdminE
          EpsilonAdmin
          last edited by

          Yes, you can do that. But it will need some coding.

          First of all, we need to extract a PDF link or file path from the post. It should be done at indexing stage, inside the 'wpfts_index_post' hook function.

          After the link/path extraction, we should read this file and extract the text information from it. It still should be done inside the same hook.

          Okay, when we have the text, we put it to one of the index clusters (your preference) and let it to the indexer to make its job as well.

          The final code will depend from the way how you have attached the PDF file to the parent post. It can be done using very different ways.

          Please give me some more explanation of this and I will post the semi-ready code here.

          https://e-wm.org

          1 Reply Last reply Reply Quote 0
          • First post
            Last post

          Suggested Topics

          • EpsilonAdminE

            [Solved] EduMall theme does not show Smart Excerpts and broken the search results page

            Watching Ignoring Scheduled Pinned Locked Moved Recipes and Known Solutions
            1
            0 Votes
            1 Posts
            519 Views
            No one has replied
          • EpsilonAdminE

            [Solved] Polylang limits search by language taxonomy

            Watching Ignoring Scheduled Pinned Locked Moved Recipes and Known Solutions fix patch polylang search taxonomy
            1
            0 Votes
            1 Posts
            774 Views
            No one has replied
          • EpsilonAdminE

            Protect attachment file from downloading (without plugins)?

            Watching Ignoring Scheduled Pinned Locked Moved Recipes and Known Solutions
            1
            0 Votes
            1 Posts
            699 Views
            No one has replied
          • EpsilonAdminE

            [Solved] Does not show Smart Excerpt with Total Theme

            Watching Ignoring Scheduled Pinned Locked Moved Recipes and Known Solutions smart excerpt total theme theme
            1
            0 Votes
            1 Posts
            623 Views
            No one has replied
          • EpsilonAdminE

            [Solved] The plugin shows wrong results for search with BeTheme template

            Watching Ignoring Scheduled Pinned Locked Moved Recipes and Known Solutions betheme theme
            1
            0 Votes
            1 Posts
            797 Views
            No one has replied

          Additional Resources

          • My Account
          • Buy WPFTS Pro
          • Community Forum
          • Affiliate Program
          • Privacy Policy
          • Terms & Conditions
          • Contact Us
          • Coupon Partner

          Be the first to read the news!

          We are always improving our products, adding new functions and fixes. Subscribe now to be the first to get the updates and stay informed about our sales! We are not spammy. Seriously.

          Join Us Now!

          We are a professional IT-team. Many of us have been working in a Web IT field for more than 10 years. Our advanced experience of software development has been employed in the creation of the WordPress FullText Search plugin. All solutions implemented into the plugin have been used for 5 or more years in over 60 different web-projects.

          We are looking forward to your comments, requests and suggestions in relation to the current plugin and future updates.

          ewm-logo-450

          The forum powered by NodeBB | Contributors