WordPress.org

Support

Support » Plugins and Hacks » Hacks » [Resolved] the_content filter (Template)

[Resolved] the_content filter (Template)

  • seogroup

    @seogroup

    Hi everybody,

    at first i hope i can explain what i mean. English is not my native language.

    I have programmed a plugin. Inside this plugin i was including via shortcode a template to my content. This was working fine. But now i have the problem that my content become a custom post type called (wppi). Now i have the problem that the_content is filled with text. But it must be filled with my template (my template gets several custom fields and pictures and shows it in single view).

    My actual solution for this problem looks like this:

    function wppi_theme_content_filter($content) {
    		 $post = $GLOBALS['post']->ID;
     		 $ntype = get_post_type($post);
    		 //echo $ntype;
    	if ($ntype == 'wppi')
    	{
    		 $wppi_description = get_the_content($post);
    	     wp_product_includer_template_two_cols_left_2($post, $wppi_description);
      	} else {
    		print_r ($content);
    	}
    }
    		add_filter( 'the_content', 'wppi_theme_content_filter' );

    In this function i add my template to the_content and it works.
    The problem in this function is the else

    print_r ($content);

    This shows only text (i know it is just print_r). So what can i do that when my post is not CP (wppi) the_content is untouched.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Filters are not printing the content directly. You get the content as argument to your filter function, possibly modify it and then just return it (return $content).

    Imagine this:
    You may have multiple filters doing something with the content, if one prints the content before the other filters in the chain finished their work you end up having multiple outputs.

    I think your whole approach is questionable, though. You should have a look at the Template Hierarchy.

    seogroup

    @seogroup

    Hi dc5ala,

    thanks for the tip, it was a good one. A normal return solves my problems. Sometimes i stay in the forest and can not see the tree. And many thx for the link. The most things there i was knowing but the hirachical structure from custom posts was new for me.

    🙂

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Resolved] the_content filter (Template)’ is closed to new replies.
Skip to toolbar