wordpress coders: question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fris
    Too lazy to set a custom title
    • Aug 2002
    • 55679

    #1

    wordpress coders: question

    Anyone know why one of them is working and one isnt?

    im just counting the number of images in a post

    <?

    // doesnt work

    function postcount() {
    global $post;
    $content = $post->post_content;
    preg_match_all('/<img/', $content, $images);
    echo count($images[0]);
    }

    // works
    function postcount() {
    global $wpdb, $id;
    $post = $wpdb->get_var("SELECT post_content FROM $wpdb->posts WHERE ID = $id");
    $post_content = apply_filters('the_content', $post);
    preg_match_all('/<img/', $post_content, $images);
    echo count($images[0]);
    }

    ?>
    Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.
  • daniel_webcams
    Confirmed User
    • Nov 2008
    • 2491

    #2
    hi...
    Because in the second you extract something from the data base... and display the results by applying the filters to format the results...

    The first one is not working first, because you don't have content (you don't take out anything from the data base)... this is the reason
    Daniel,

    Skype: [email protected]
    ICQ: 354-220-339
    Email: daniel@adultforce[dot]com


    Comment

    • fris
      Too lazy to set a custom title
      • Aug 2002
      • 55679

      #3
      cause global $post saves $post->ID; $post->post_content; etc and everything from the current post, figured it would do the same
      Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.

      Comment

      • Libertine
        sex dwarf
        • May 2002
        • 17860

        #4
        Originally posted by fris
        cause global $post saves $post->ID; $post->post_content; etc and everything from the current post, figured it would do the same
        Doesn't $post->post_content give the content without formatting, just like get_the_content()?

        If so, you might want to check this out: http://www.web-templates.nu/2008/08/...th-formatting/
        /(bb|[^b]{2})/

        Comment

        Working...