WPFTS Pro Main Site

    WPFTS Community Forum

    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Popular
    Get WPFTS Pro today with 25% discount!

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

    Recipes and Known Solutions
    smart excerpt wpquery
    2
    3
    462
    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.
    • EpsilonAdmin
      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
        • EpsilonAdmin
          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

          • EpsilonAdmin

            [Solved] The Astra theme does not show Smart Excerpt for files
            Recipes and Known Solutions • • EpsilonAdmin

            1
            0
            Votes
            1
            Posts
            331
            Views

            No one has replied

          • EpsilonAdmin

            [Solved] Polylang limits search by language taxonomy
            Recipes and Known Solutions • fix patch polylang search taxonomy • • EpsilonAdmin

            1
            0
            Votes
            1
            Posts
            392
            Views

            No one has replied

          • EpsilonAdmin

            [Solved] Indexing and Search files by content in BuddyDrive
            Recipes and Known Solutions • buddydrive file search • • EpsilonAdmin

            1
            0
            Votes
            1
            Posts
            407
            Views

            No one has replied

          • EpsilonAdmin

            [Solved] Files not shown in TemplateToaster theme search results
            Recipes and Known Solutions • templatetoaster theme search • • EpsilonAdmin

            1
            0
            Votes
            1
            Posts
            338
            Views

            No one has replied

          • EpsilonAdmin

            [Solved] How to index new posts which was added by the script?
            Recipes and Known Solutions • reindex script search • • EpsilonAdmin

            1
            0
            Votes
            1
            Posts
            368
            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