• Resolved fjellf

    (@fjellf)


    Hi!

    Thanks for a great plugin!

    I have a static front page showing latest posts, and trying to get a post which has an image uploaded to it appear on top of the front page.

    Tried the “sort posts by most recent modified approach” which worked manually for post id 110, but not programmatically.

    I put this in index.php to sort by modified:

    <?php
    if ( is_home() ) {
    	query_posts($query_string . '&orderby=modified&order=desc');
    }
    ?>

    I put this in single.php to get the upload form:

    <?php echo do_shortcode( '[fu-upload-form]' ); ?>

    And I put this in functions.php to update post 110:

    add_action( 'fu_after_upload', 'my_fu_after_upload' );
    function my_fu_after_upload( $attachment_ids ) {
      $my_post = array(
          'ID'           => 110,
          'post_content' => 'updated content'
      );
      wp_update_post( $my_post );
    }

    This all works fine, with post 110 appearing on top of my front page after image upload, but I just can´t figure out how to grab the post id for any post, not manually just for post 110.

    Any input on how to grab the post id in the action would be highly appreciated 🙂

    (I run WP 3.8.1 with twentytwelve theme)

    https://wordpress.org/plugins/frontend-uploader/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter fjellf

    (@fjellf)

    Figured it out 🙂

    Replaced “110” with $id_a = $_POST['post_ID'];

    $id_a = $_POST['post_ID'];
    
      $my_post = array(
          'ID'           => $id_a,
          'post_content' => 'This is the updated content.'
      );

    Odd, as I thought I already tried this approach.

    Plugin Author Rinat

    (@rinatkhaziev)

    Glad that you figured it out! 🙂 on an unrelated note:
    You should avoid using query_posts because it modifies main page query and that can result in weird things happening.

    Plugin Author Rinat

    (@rinatkhaziev)

    Marking as resolved

    Renat nice plugin , it’s working fine ,my problem is –

    1) when i uploading any file i want that that file should show on same page and when i click it should be download .

    2) I want to add custom fields and i want to store that details(when user input) and it should be show in admin panel .

    gsmamitsingh@gmail.com

    thanks in advance

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Have post appear on top of front page after image upload- can´t grab post id’ is closed to new replies.