0

I edited the plugin WP User Frontend (for editing posts from frontend) to have two different edit pages for two different post types. Here's the original function which handles the edit_link.

function wpuf_edit_post_link( $url, $post_id ) {
if ( is_admin() ) {
    return $url;
}

$override = wpuf_get_option( 'override_editlink', 'yes' );
if ( $override == 'yes' ) {
    $url = '';
    if ( wpuf_get_option( 'enable_post_edit' ) == 'yes' ) {
        $edit_page = (int) wpuf_get_option( 'edit_page_id' );
        $url = get_permalink( $edit_page );

        $url = wp_nonce_url( $url . '?pid=' . $post_id, 'wpuf_edit' );
    }
}

return $url;
}

add_filter( 'get_edit_post_link', 'wpuf_edit_post_link', 10, 2 );

How can I call the current post parameters inside the function? I used get_post but it doesn't work (I guess because it's not inside the loop...). Here's the piece of function I edited. 201 and 203 are correct edit pages IDs: inside the pages there is some shortcode which turns them into an edit page.

$override = wpuf_get_option( 'override_editlink', 'yes' );
if ( $override == 'yes' ) {
    $url = '';
    if ( wpuf_get_option( 'enable_post_edit' ) == 'yes' ) {

    $post = get_post($post_id);

    if ($post->post_type == 'type1') {
        $url = get_permalink( 201 );
        $url = wp_nonce_url( $url . '?pid=' . $post_id, 'wpuf_edit' );
    }

    if ($post->post_type == 'type2') {
        $url = get_permalink( 203 );
        $url = wp_nonce_url( $url . '?pid=' . $post_id, 'wpuf_edit' );
    }
    }
}

What's wrong with this code?

1 Answer 1

0

Instead of using $post = get_post($post_id);, you can call global $post; which will load the value of the current post assuming that you have not triggered any other loops.

3
  • I have other loops in the page (on the sidebar)... but I put wp_reset_postdata at the end of the loops. Will this work? I'm trying rigth now.
    – She Hulk
    Commented Feb 15, 2013 at 21:13
  • no, it didn't work :( I tryed putting global $post; instead of get_post and also tryed to move it at the beginning of the function, but nothing :(
    – She Hulk
    Commented Feb 15, 2013 at 21:40
  • wait, I was doing a stupid mistake with $url2 (it must be $url in both if statements), it works with global $post;, thanks Christopher! I edited the $url detail in my original post.
    – She Hulk
    Commented Feb 16, 2013 at 10:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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