Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am looking for what params are passed to my filter function. Where can I find such info in the codex?

http://codex.wordpress.org/Plugin_API/Filter_Reference/the_content didn't provide much info

I wanted to know if the post is a child of another

share|improve this question

2 Answers 2

up vote 5 down vote accepted

I don't think there are any additional parameters passed, per se, to the_content, but global variables like $post are accessible.

So something like this would work:

add_filter( 'the_content', 'check_for_post_parent' );

function check_for_post_parent($content) {
     global $post;
     if ($parent_id == $post->post_parent) {
          //do what you want to $content here, 
          //now that you know $parent_id
          //...
          }
     return $content;
     }
share|improve this answer

In wp-includes/post-template.php you’ll find the place, where the filters are applied:

/**
 * Display the post content.
 *
 * @since 0.71
 *
 * @param string $more_link_text Optional. Content for when there is more text.
 * @param string $stripteaser Optional. Teaser content before the more text.
 */
function the_content($more_link_text = null, $stripteaser = 0) {
    $content = get_the_content($more_link_text, $stripteaser);
    $content = apply_filters('the_content', $content);
    $content = str_replace(']]>', ']]>', $content);
    echo $content;
}

The only parameter is the content text.

But you can always use the global variable $post to get more information about the currently used post. Try the following snippet in your theme’s functions.php:

/*
 * Priority 100 to let other filters do their work first.
 */
add_filter( 'the_content', 'debug_post_info', 100 );
/**
 * Print information about the current post.
 *
 * @param  string $content
 * @return string
 */
function debug_post_info( $content )
{
    return $content . '<hr><pre>' . var_export( $GLOBALS['post'], TRUE ) . '</pre>';
}

On a child page you get some nice data:

stdClass::__set_state(array(
   'ID' => 2168,
   'post_author' => '2',
   'post_date' => '2007-09-04 09:52:18',
   'post_date_gmt' => '2007-09-03 23:52:18',
   'post_content' => 'This page has a parent.',
   'post_title' => 'Child page 2',
   'post_excerpt' => '',
   'post_status' => 'publish',
   'comment_status' => 'open',
   'ping_status' => 'open',
   'post_password' => '',
   'post_name' => 'child-page-2',
   'to_ping' => '',
   'pinged' => '',
   'post_modified' => '2007-09-04 09:52:18',
   'post_modified_gmt' => '2007-09-03 23:52:18',
   'post_content_filtered' => '',
   'post_parent' => 2167,
   'guid' => 'http://wpthemetestdata.wordpress.com/parent-page/child-page-1/child-page-2/',
   'menu_order' => 0,
   'post_type' => 'page',
   'post_mime_type' => '',
   'comment_count' => '0',
   'ancestors' => 
  array (
    0 => 2167,
    1 => 2166,
  ),
   'filter' => 'raw',
))

'post_parent' => 2167 is the ID of the parent post. On pages without a parent the parameter is set to 0.

share|improve this answer
    
I get so inspired when I read your bits of info. Thanks, very very much! I had a vague understanding of this process I had just ran with, this cleared up a lot. :) –  David Apr 18 '12 at 12:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.