如何获取wordpress页面的get_permalink

时间:2015-09-05 13:26:07

标签: wordpress wordpress-plugin

我使用此功能创建WordPress页面:

function adv_activate_plugins(){
    $post_details = array(
  'post_title'    => 'بازاریابی انلاین',
  'post_name'       =>'marketing4321',
  'post_content'  => '[marketing]',
  'post_status'   => 'publish',
  'post_author'   => 1,
  'post_type' => 'page'
   );
   wp_insert_post( $post_details );

   }

如何get_permalink该页面?

2 个答案:

答案 0 :(得分:2)

    mToolbar.setVisibility(View.VISIBLE);
    mToolbar.setTitle(getToolbarTitle());
    setSupportActionBar(mToolbar);
    if (hasDrawerToggle()) {
        mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerMainLayout,
                R.string.drawer_open, R.string.drawer_close);
        mDrawerToggle.setDrawerIndicatorEnabled(true);
        mDrawerMainLayout.setDrawerListener(mDrawerToggle);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeButtonEnabled(true);
    }



@Override
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
        // Sync the toggle state after onRestoreInstanceState has occurred.
        if (hasDrawerToggle()) {
            mDrawerToggle.syncState();
        }
    }

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    if (hasDrawerToggle()) {
        mDrawerToggle.onConfigurationChanged(newConfig);
    }
}

如果您想在功能之外使用它:

$id = wp_insert_post($post_details);
$permalink = get_permalink($id);

答案 1 :(得分:0)

尝试使用以下代码来帮助您解决问题,

function get_permalink_by_post_name($post_name){
   global $post;
   global $wpdb;
   $id = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_name = '".$post_name."'");    
   return get_permalink($id);    
}

echo get_permalink_by_post_name('post-name');