• I’ve added a custom post type to the list of items to display in search results. The post_content of these posts has a shortcode encapsulating the content. I am trying to process the shortcode so that search results for this custom post type will display some content, but so far I’ve failed. What I have right now in my plugin file (simplied for relevant code) is:

    
    final class darwin_core {
    private function setup() {
    add_action('init', array($this, 'dwc_add_shortcodes_to_excerpt' ) );
    }
    
    function dwc_add_shortcodes_to_excerpt() {
    add_filter( 'get_the_excerpt', 'do_shortcode');
    add_shortcode( 'dwc-post-content', array( $this, 'dwc_post_content_shortcode' ) );
    }
    
    public function dwc_post_content_shortcode( $atts, $content = '', $tag = '' ) {
    return "testing";
    }
    }

    I am certain that setup() is being called.

    Example post_content:
    [dwc-post-content id="55575"]Chondrichthyes[/dwc-post-content]

    I’ve tried a lot of variants of this configuration but nothing has worked. Do you have an idea of what I’m missing?

    • This topic was modified 5 years, 5 months ago by atmojones.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author BuddyBoss

    (@buddyboss)

    Hello @atmojones

    Could you please share more info about how did you call the setup function?
    Seems you have created private function and it is not calling under the class.

    Please share the setup calling code which will help us to debug.

    Thanks

    Thread Starter atmojones

    (@atmojones)

    Sorry for my lack of response. Got busy with other more important features.

    I think I’ve figured this out. My posts do not have post_excerpt set in the database, the excerpts I was trying to alter were the auto generated excerpts. These are generated off post_content with shortcodes stripped rather than processed.

    The easiest solution I have found is returning an excerpt generated from $post->post_content using the filter get_the_excerpt (because post_content has already had the shortcodes applied at this point, and then wp_trim_excerpt doesn’t do anything but return the excerpt you generated).

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Shortcodes in excerpt of custom post type’ is closed to new replies.