Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why isn't apply_filter('the_content') outputting anything?

I've tried so many combinations of php to get wordpress to output $post->post_content as formatted text (as opposed to the raw formatting that echo $post->post_content gives me. This combination seems to be the most promising, but it isn't outputting anything. Any ideas?

(it's this line: <?php $content = apply_filters('the_content', $s->post_content); ?>)

<?php query_posts('orderby=menu_order&order=asc&posts_per_page=-1&post_type=page&post_parent='.$post->ID); if(have_posts()) { while(have_posts()) { the_post(); ?>
    <div class="page">
        <?php
            global $wpdb;
            $subs = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_parent='$post->ID' AND post_type='page' AND post_status='publish'");
            if($subs) {
        ?>
        <div class="navi"></div>
        <a class="naviNext"><img src="<?php bloginfo('template_url'); ?>/images/navi-next.png" alt="" /></a>
        <div class="scrollable">
            <div class="items">
                <?php foreach($subs as $s) { ?>
                <div class="item">
                    <h2><?php echo $s->post_title; ?></h2>
                    <?php $content = apply_filters('the_content', $s->post_content); echo $content; ?>
                </div>
                <?php } ?>
            </div>
        </div>
        <?php } else { the_content(); } ?>
    </div>
    <?php } } wp_reset_query(); ?>
like image 359
HandiworkNYC.com Avatar asked Aug 30 '10 17:08

HandiworkNYC.com


People also ask

How to know if the filter result is not completely complete?

Case 1. The Filter Function Is Not Valid Case 2. The Filter Icon Is Greyed Out Case 3. The Filter Result Is Not Complete When you use Excel to edit tables, there may be many values. To find certain values, the Filter feature is very useful. How to filter in Excel? There are mainly 3 ways for you. Way 1. Use the Sort & Filer icon.

Why is my filter not valid?

Sometimes, when you run a Filter function, you may receive the error “that function is not valid”. In this case, please check whether you are an Office 365 subscriber. Case 2. The Filter Icon Is Greyed Out The cause of this issue may be that your grouped worksheets.

Why are my filters not working in Office 365?

Case 1. The Filter Function Is Not Valid Sometimes, when you run a Filter function, you may receive the error “that function is not valid”. In this case, please check whether you are an Office 365 subscriber. Case 2. The Filter Icon Is Greyed Out The cause of this issue may be that your grouped worksheets.

How to use the filter function in Excel?

Right-click a cell and choose the Filter option. This method allows you to filter the column according to value, color, and icon of the selected cell. Way 3. Use the Excel filter function. Using the Filter function can filter values more flexibly. But please note that this feature is currently only available for Office 365 subscribers.


3 Answers

As far as I know, the function that applies the main 'formatting' to the content body is wpautop(). That function should be hooked into 'the_content' by wordpress. The function does do annoying things (like mess up embed code) though and there are a lot of plugins that will unhook it from the filter stack. Try replacing your line:

<?php $content = apply_filters('the_content', $s->post_content); echo $content; ?>

with

<?php $content = wpautop($s->post_content); echo $content; ?>

If that helps then you probably have an issue of the wpautop getting unhooked somewhere.

like image 185
spuriousdata Avatar answered Nov 15 '22 08:11

spuriousdata


I had the same problem. It turned out there was a function in my theme, that also filtered the content, but had a bug in it, causing the filter to return an empty string.

So check your theme and plugins for functions that filter the_content. In Sublime Text 2 for example you can do a quick "find in files" with ⌘/CTRL + + F to find possible culprits.

like image 37
Gchtr Avatar answered Nov 15 '22 08:11

Gchtr


man86,

I see you are getting the post data via $wpdb->get_results(). The thing about it is that the data is returned raw, so you need to "prepare it" before you are able to use common post functions such as the_content() (which will return the content already formatted, like you'd like it to).

How about trying this (see comments on code):

<?php query_posts('orderby=menu_order&order=asc&posts_per_page=-1&post_type=page&post_parent='.$post->ID); 

if(have_posts()) { while(have_posts()) { the_post(); ?>
<div class="page">
    <?php
        global $wpdb;
        $subs = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_parent='$post->ID' AND post_type='page' AND post_status='publish'");
        if($subs) { ?>
    <div class="navi"></div>
    <a class="naviNext"><img src="<?php bloginfo('template_url'); ?>/images/navi-next.png" alt="" /></a>
    <div class="scrollable">
        <div class="items">
            <?php foreach($subs as $post) { // <-- changed $s to $post
            setup_postdata($post) // <--use setup_postdata to prepare post
             ?>
            <div class="item">
                <h2><?php the_title(); // <-- use "the_title() now that the data has been prepared ?></h2>
                <?php the_content(); // <-- use "the_content() now that the data has been prepared ?>
            </div>
            <?php } ?>
        </div>
    </div>
    <?php } else { the_content(); } ?>
</div>
<?php } } wp_reset_query(); ?>

Reference: http://codex.wordpress.org/Class_Reference/wpdb#Examples_5 ("Get all information on the Drafts by User 5")

Thanks, I hope that helps!

Vq.

like image 42
Vidal Quevedo Avatar answered Nov 15 '22 07:11

Vidal Quevedo