Forum Replies Created

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter alfiethecoder

    (@alfiethecoder)

    I think the problem is something to do with caching, although I don’t have the time to truly dig into this. I’ve replaced my code with:

    if ( !empty($current_page) ) {
      $_current_page = get_page( $current_page );
    
      global $wpdb;
      if ( !empty($_current_page->post_parent) && ($_current_page->ID != $_current_page->post_parent) && !isset($_current_page->ancestors) ) {
        $id = $_current_page->ancestors[] = $_current_page->post_parent;
    
        while ( $ancestor = $wpdb->get_var( $wpdb->prepare("SELECT <code>post_parent</code> FROM $wpdb->posts WHERE ID = %d LIMIT 1", $id) ) ) {
    
        if ( $id == $ancestor )
          break;
    
          $id = $_current_page->ancestors[] = $ancestor;
        }
    }

    So I’ve effectively copied the code from _get_post_ancestors and forced it to execute in my routine, and it works. But calling get_post_ancestors doesn’t, because the code simply returns the cached copy of a post’s ancestors field, which contains nothing, even when the post does genuinely have ancestors.

    Thanks for your help Michael: perhaps this needs to be looked into elsewhere, unless it’s just me – but I’m not doing anything I shouldn’t be!

    Thread Starter alfiethecoder

    (@alfiethecoder)

    Thanks for helping with this Michael. Here’s the weird thing. If I replace the code above with this:

    if ( !empty($current_page) ) {
    	$_current_page = get_page( $current_page );
    	$myancestors= get_post_ancestors($_current_page);
             if ( in_array($page->ID, (array) $myancestors) ) {
                 $css_class .= ' current_page_ancestor';
             }

    then after the call to get_post_ancestors $myancestors is still empty!

    Thread Starter alfiethecoder

    (@alfiethecoder)

    That’s true, but

    i) It doesn’t explain why the function isn’t returning the correct value.

    ii) I actually need the hierarchy, not simply the single parent. Ancestors would give me all ancestors, post_parent will only give me the parent.

    Download a theme that already does it, like Cutline and then modify to suit you.

    I got fed up with this not working in 2.5 and 2.6. So I wrote a very simple command line script that runs every 10 mins and publishes scheduled posts. Simple, and it works a treat:

    The script says this:

    mysql --user=DBUSERNAME --pass=DBPASSWORD DBNAME < publish_posts.sql >> publish_posts.log

    Obviously replace the capitalised bits with the appropriate values from your wp-config.php.

    The file “publish_posts.sql” says this:

    update wp_posts
    set post_status='publish'
    where post_status='future' and
    post_date <= now()
    \g

    Probably won’t go down well with the purists, but it works for me!

    At last – the Disable Flash plugin has finally sorted this out. What a nightmare.

    Moral: don’t use technology that doesn’t work for everyone. WordPress is great, but this is v. frustrating!

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