Title: wordpress environment in amfphp
Last modified: August 19, 2016

---

# wordpress environment in amfphp

 *  Resolved [trevorhartman](https://wordpress.org/support/users/trevorhartman/)
 * (@trevorhartman)
 * [17 years, 1 month ago](https://wordpress.org/support/topic/wordpress-environment-in-amfphp/)
 * Hi,
 * I’m using AMFPHP to get wordpress data into flash / as3. AMFPHP services reside
   in a separate directory from wordpress. I need access to the wordpress environment
   to call functions like wp_get_attachement_url. I tried including post.php like
   so:
 * include_once(‘../../../wordpress/wp-includes/post.php’);
 * But my service returns:
    Fatal error: Call to undefined function wp_cache_get()
   in /Users/thartman/Sites/wordpress/wp-includes/post.php on line 226
 * Is there a proper way to include the wp enviro so I have access to the wealth
   of functions?
 * thanks,
    Trevor

Viewing 7 replies - 1 through 7 (of 7 total)

 *  Thread Starter [trevorhartman](https://wordpress.org/support/users/trevorhartman/)
 * (@trevorhartman)
 * [17 years ago](https://wordpress.org/support/topic/wordpress-environment-in-amfphp/#post-1018962)
 * +1
 * any ideas? or links to other forums? thx – trevor
 *  [whooami](https://wordpress.org/support/users/whooami/)
 * (@whooami)
 * [17 years ago](https://wordpress.org/support/topic/wordpress-environment-in-amfphp/#post-1018963)
 * > get wordpress data …
 * this is a common enough issue that you could have searched and found it — its
   even in the codex.
 * To use any wordpress functions outside of wordpress you need to include wp-blog-
   header.php
 *  Thread Starter [trevorhartman](https://wordpress.org/support/users/trevorhartman/)
 * (@trevorhartman)
 * [17 years ago](https://wordpress.org/support/topic/wordpress-environment-in-amfphp/#post-1018964)
 * thanks. i had tried this but get an error:
 * Fatal error: Call to a member function set_prefix() on a non-object in /Users/
   thartman/Sites/wordpress/wp-settings.php on line 255
 *  [whooami](https://wordpress.org/support/users/whooami/)
 * (@whooami)
 * [17 years ago](https://wordpress.org/support/topic/wordpress-environment-in-amfphp/#post-1018965)
 * searchable:
 * [http://wordpress.org/support/topic/174783?replies=16](http://wordpress.org/support/topic/174783?replies=16)
 *  Thread Starter [trevorhartman](https://wordpress.org/support/users/trevorhartman/)
 * (@trevorhartman)
 * [17 years ago](https://wordpress.org/support/topic/wordpress-environment-in-amfphp/#post-1018966)
 * **solution**:
 * if you’re using amfphp and you need access to wordpress, open up globals.php 
   under amfphp and include wp-blog-header.php at the end of the file (right before“?
   >” )
 * example:
    require_once “../wordpress/wp-blog-header.php”;
 * [@whooami](https://wordpress.org/support/users/whooami/): thx for your help, 
   and fyi, i searched my face off before posting. im a php noob, amfphp noob and
   wordpress noob (but not a programming noob) so i probably wasn’t using the right
   terms.
 *  [brasofilo](https://wordpress.org/support/users/brasofilo/)
 * (@brasofilo)
 * [16 years, 7 months ago](https://wordpress.org/support/topic/wordpress-environment-in-amfphp/#post-1019010)
 * trevor,
    thanks a lot for posting the solution!!
 * i guess wp 2.8 broke the classic amfphp, some functions are not working, but 
   some ARE
 * since I’m still in AS2, i can’t jump to something like Zend that maybe working
   flawless… whatever… i digress…
    THANKS AGAIN
 *  [brasofilo](https://wordpress.org/support/users/brasofilo/)
 * (@brasofilo)
 * [16 years, 7 months ago](https://wordpress.org/support/topic/wordpress-environment-in-amfphp/#post-1019013)
 * hi there,
    for anyone working amfphp and wordpress
 * i just made this two functions that may be usefull
 * Get Image: get the url of the first image attachment of a given post
 *     ```
       /**
       		 * Gets the first image of a post of the requiered type
       		 * .
       		 * .
       		 *  @param $ID post_id
       		 *  @param $type thumbnail, medium, large, full
       		 *  @returns File URL or Null
       		 */
       		function get_image($ID, $type) {
       			if($ID!='')
       			{
       				if ( $images = get_children(array(
       					'post_parent' => $ID,
       					'post_type' => 'attachment',
       					'numberposts' => 1,
       					'post_mime_type' => 'image')))
       				{
       					foreach( $images as $image ) {
       						// $attachmenturl=wp_get_attachment_url($image->ID);
       						$attachmentimage=wp_get_attachment_image_src( $image->ID, $type );
       						// $imagelink=get_permalink($image->post_parent);
       					}
       				}
       				return $attachmentimage[0];
       			}
       			else
       			{
       				return;
       			}
       		}
       ```
   
 * Get Pages Menu: returns all pages with order different than 0, and their subpages(
   this function uses EzSQL, so you have to adapt the queryes it if you don’t use
   this adapter)
 *     ```
       /**
       		 * Gets all the pages that don't have page_order=0, so you can exclude pages from this menu assigning 0 to them.
       		 * This function can be expanded to get a third level of submenus.
       		 * .
       		 * .
       		 *  @returns Array of objects, the first item is the first level, the others are second levels, all levels are ordered by page_order
       		 */
       		 public function get_menu() {
       			$pages = $this->db->get_results(" SELECT ID, post_title, post_name from wp_posts where post_status='publish' AND post_parent='0' AND post_type='page' AND not menu_order='0'  ORDER BY menu_order ASC ");
       			$menu[0] = $pages;
       			$count = 1;
       			foreach ( $pages as $page )
       			{
       				$subpages = $this->db->get_results(" SELECT ID, post_title, post_name, post_parent from wp_posts where post_status='publish' AND post_parent='".$page->ID."' AND post_type='page' AND not menu_order='0'  ORDER BY menu_order ASC");
       				if ($this->db->num_rows>0)
       				{
       					$menu[$count] = $subpages;
       					$count++;
       				}
       	            //echo $user->name;
       	            //echo $user->email;
       			}
       			return $menu;
       		}
       ```
   

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘wordpress environment in amfphp’ is closed to new replies.

## Tags

 * [amfphp](https://wordpress.org/support/topic-tag/amfphp/)
 * [as3](https://wordpress.org/support/topic-tag/as3/)
 * [environment](https://wordpress.org/support/topic-tag/environment/)
 * [functions](https://wordpress.org/support/topic-tag/functions/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 7 replies
 * 3 participants
 * Last reply from: [brasofilo](https://wordpress.org/support/users/brasofilo/)
 * Last activity: [16 years, 7 months ago](https://wordpress.org/support/topic/wordpress-environment-in-amfphp/#post-1019013)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
