php - wordpress get all publish pages permalinks -


i want permalinks of published pages , export excel file.

what best solution?

  • should go wp-admin panel , copy-paste permalinks on page editor?
  • can export data using mysql query?

it possible difficult via sql query, because wordpress allows change permalink structure - sql query need regard permalink options build correct permalink when query executed.

and guess looking way not require copy paste links admin page ;-)

by far best , easiest thing write small script runs export within wordpress , uses functions get_pages , get_permalink:

// list of published pages wordpress. $pages = get_pages( 'post_status=publish' );  // loop through pages , fetch permalink each page. ( $pages $page ) {   $permalink = get_permalink( $page->id );   // permalink now... } 

note: code run inside wordpress, i.e. as plugin or inside theme. how excel export beyond scope of answer...


personally i'd create wordpress plugin (there many guides out there on how works, like one). in plugin check url param, , if param present export data. additionally check if user requests export has admin permissions before exporting data.

a bit this:

/**   * wordpress plugin header...   */  $allowed = false; $requested = false;  // check if current user has admin capabilies. if ( current_user_can( 'manage_options' ) ) { $allowed = true; }  // check if user requested export. // i.e. calling url http://yoursite.com?export_permalinks=1 if ( 1 == $_get['export_permalinks'] ) { $requested = true; }  if ( $requested && $allowed ) {   // 1. list of published pages wordpress.   $pages = get_pages( 'post_status=publish' );    // 2. build export data.   $export = array();   ( $pages $page ) {     $permalink = get_permalink( $page->id );     $export[] = array( $page->id, $permalink );   }     // 3. export data (i var_dump example).    var_dump( $export );     // we're done, don't execute else.    exit; } 

please note code should explain suggested workflow. not use best practices , don't recommend use on live site


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -