Forums

[resolved] add_filter (the_content... makes content dissapear (7 posts)

  1. knewton
    Member
    Posted 11 months ago #

    Hi. I created a plug-in to use in my web site that adds content to a custom post type (audio_music). The plug-in works great for my custom posts but on all other pages the content is not shown. Only the title of the post and the comments box remains. Whenever I remove the filter ( add_filter ('the_content', 'my_filter_the_content')) the other pages and posts work fine but my plug in is broken. The same happens when I deactivate the plugin. There are no other plugins running when I test this. Suggestions? Here is the code:

    [code moderated - please use the http://pastebin.com/ ]

  2. knewton
    Member
    Posted 11 months ago #

    correction - the post type is called "audio_posts" not "audio_music"

  3. alchymyth
    The Sweeper
    Posted 11 months ago #

    http://codex.wordpress.org/Plugin_API#Create_a_Filter_Function

    don't echo or print any output from within a filter - the filter needs to return the content.

  4. knewton
    Member
    Posted 11 months ago #

    So I changed 'echo' to 'return' and I still have the same issue. Suggestions?

  5. alchymyth
    The Sweeper
    Posted 11 months ago #

    please paste the code of your plugin into a http://pastebin.com/ and post the link to it here.

  6. knewton
    Member
    Posted 11 months ago #

  7. knewton
    Member
    Posted 11 months ago #

    I fixed the issues by adding this:

    function audio_accessible($content) {
    		/* If this is NOT audio_post (custom post type), then simply return the content*/
    	if (!is_singular ('audio_posts')) {
    
    			return $content;
    		}

    [Please post code snippets between backticks or use the code button.]

Reply

You must log in to post.

About this Topic