WordPress.org

Ready to get started?Download WordPress

Forums

get_permalink returns default link (2 posts)

  1. Iperdesign_IT
    Member
    Posted 1 year ago #

    Hi guys, I hope you can help me.

    So i'm using /%postname%/ as permalink structure, and my htaccess is this:

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /develop/sekai/
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /develop/sekai/index.php [L]
    </IfModule>
    
    # END WordPress

    Hovewer, get_permalink returns me the default permalink structure (?page_id=x), while menus are fine with their links. What should i do? Thanks for all!! :D

  2. klahla
    Member
    Posted 1 year ago #

    I was working on front-end submission form and encounted a similar issue. Then understood how and why it works this way.

    Code looked something like this:

    if ( ... ) { $pstatus = "post"; }
           else { $pstatus = "draft"; }
    
    $new_post = array( ...
      'post_status' => $pstatus );
    $post_id = wp_insert_post($new_post);
    $link = get_permalink($post_id);
    echo $link;

    Here is the deal.

    When you submit post as a DRAFT,
    admin/editor can change the permalink before it is ever posted.
    The post slug ($post->post_name;) simply does not exist yet.
    So returning "?page_id=" is the only option wordpress has.

    If you submit post as a POST,
    then everything works perfectly as expected.

    Hope it helped.

Topic Closed

This topic has been closed to new replies.

About this Topic