Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author dreamsofmatter

    (@stratoponjak)

    Hi!

    What does your function do?

    Thread Starter Sany

    (@sannny)

    I created a shortcode which filters and lists some posts. Some of them are standard posts, some of them contains content mirror. When I add the shortcode to the TinyMCE Editor, all works fine.

    Now I wanted to do the filtering and listing automatically without pasting my shortcode into 1000 pages (via custom fields). So i created the following function. It adds the shortcode to the_content without pasting it in the editor, it is only mentioned in PHP.

    function post_filter($content)
    {
       global $post;
       global $content_is_mirror;
    
       // Metadata/ Custom Fields
       $version = get_post_meta($post->ID, 'version', true);
       $product = get_post_meta($post->ID, 'product', true);
       $status = get_post_meta($post->ID, 'post_status', true);
    
       // Posts with Content Mirror Shortcode
       if (isset ( $content_is_mirror )) { return; }
    
       $content .= '<h1>Filter</h1>';
    
       $content .= do_shortcode('[posts version="' . $version . '" product="' . $product . '" post_status="' . $status . '"]');
    
       return $content;
    }
    add_filter('the_content','post_filter');

    If I add this line, the page is broken (only on pages that contain posts with content mirror):

    $content .= do_shortcode('[posts version="' . $version . '" product="' . $product . '" post_status="' . $status . '"]');

    So i added a temporary solution (found on the FAQs of this plugin):

    global $content_is_mirror;
       if (isset ( $content_is_mirror )) { return; }

    Now, the site is fine, it shows all what it should.
    BUT my table of contents does not appear anymore, maybe because I did a return, but nothing else seems to fix it.
    If I echo the shortcode, all is fine (but without table of contents), but I really need to add it to post content, because it is important for generating a table of contents.

    Now I suppose the reason is
    $content .= ...
    return $content;
    add_filter('the_content', 'post_filter');

    Plugin Author dreamsofmatter

    (@stratoponjak)

    Maybe you could try

    // Posts with Content Mirror Shortcode
    if (isset ( $content_is_mirror )) { return $content; }

    Thread Starter Sany

    (@sannny)

    I already did, but it does not change anything.

    Thread Starter Sany

    (@sannny)

    It changes something, when I do return $content the page doesn’t even load again. This is why I did only return.

    Plugin Author dreamsofmatter

    (@stratoponjak)

    Sorry that I can’t find the time help you at this moment.

    Thread Starter Sany

    (@sannny)

    Okay, thanks anyways.

    Thread Starter Sany

    (@sannny)

    I just want to inform you that I found the solution. I outcommented line 167 in contentmirror.php and it now it works. My function doesn’t need $content_is_mirror anymore. Maybe the filters don’t like each other šŸ˜‰

    //$post_content = apply_filters('the_content', $post_content);

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Content mirror posts and the_content’ is closed to new replies.