• Resolved kc11

    (@kc11)


    Hi,

    I am working on a plugin, and as part of it I have am using ‘the_post’ hook with a filter .

    when I do a var dump of ‘the_post’ I get:

    object(stdClass)[78]
      public 'ID' => int 4
      public 'post_author' => string '1' (length=1)
      public 'post_date' => string '2010-10-18 02:11:42' (length=19)
      public 'post_date_gmt' => string '2010-10-18 02:11:42' (length=19)
      public 'post_content' => string 'is here [beauty].' (length=17)
      public 'post_title' => string 'post 2' (length=6)
      public 'post_excerpt' => string '' (length=0)
      public 'post_status' => string 'publish' (length=7)
      public 'comment_status' => string 'open' (length=4)
      public 'ping_status' => string 'open' (length=4)
      public 'post_password' => string '' (length=0)
      public 'post_name' => string 'post-2' (length=6)
      public 'to_ping' => string '' (length=0)
      public 'pinged' => string '' (length=0)
      public 'post_modified' => string '2010-10-19 02:00:45' (length=19)
      public 'post_modified_gmt' => string '2010-10-19 02:00:45' (length=19)
      public 'post_content_filtered' => string '' (length=0)
      public 'post_parent' => int 0
      public 'guid' => string 'https://localhost/wordpress/?p=4' (length=31)
      public 'menu_order' => int 0
      public 'post_type' => string 'post' (length=4)
      public 'post_mime_type' => string '' (length=0)
      public 'comment_count' => string '0' (length=1)
      public 'filter' => string 'raw' (length=3)

    How can I best access the information in this object. I have been looking into the php function “get_tags”, but so far have not been able to get it to work.

    Thank you,

    KC

Viewing 4 replies - 1 through 4 (of 4 total)
  • If it’s an object then you can access the attributes as per normal PHP objects, e.g. $the_post->post_type

    Thread Starter kc11

    (@kc11)

    Hi Xephan,`

    Thanks again,

    my code is

    add_filter('the_post', ds_add_to_content);
    
    function ds_add_to_content($content) {
    
    echo ($content->post_content);

    but nothing is printed out. $content contains the loaded object of stdClass, by the way.

    KC

    Callback functions must be passed as a string or array for class methods.
    It should work once you change that to add_filter(‘the_post’, ‘ds_add_to_content’);

    Thread Starter kc11

    (@kc11)

    Xephan,

    Thanks, that worked.

    KC

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘how can I access the stdClass in a plugin’ is closed to new replies.