WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] the_content filter (Template) (3 posts)

  1. seogroup
    Member
    Posted 1 year ago #

    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.

  2. dc5ala
    Member
    Posted 1 year ago #

    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.

  3. seogroup
    Member
    Posted 1 year ago #

    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.

    :-)

Topic Closed

This topic has been closed to new replies.

About this Topic