Include Wordpress Core into own Scripts

前端 未结 3 1940
深忆病人
深忆病人 2020-12-08 08:33

I\'m trying to \"Import\" the Wordpress core into an own script to use the functionality such as wp_query etc. I\'ve created an script in a subdirectory (own framework) and

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-08 09:06

    I had the same error. I wanted to get some articles along with permalinks. This helped:

    global $wpdb, $wp_rewrite;
    require '/(...)/wp-config.php';
    
    $result = $wpdb->get_results( $wpdb->prepare( ... ) );
    foreach( $result as &$item )
      $item->link = get_permalink( $item->ID );
    

    I also found this useful in another case: http://www.stormyfrog.com/using-wpdb-outside-wordpress/

提交回复
热议问题