Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer 1

up vote 0 down vote accepted

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.

share|improve this answer
    
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 Feb 15 '13 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 Feb 15 '13 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 Feb 16 '13 at 10:12
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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