function test_getStructuredPostMeta() { $id = wp_insert_post(array("post_title" => "post one", "post_name" => "post-one")); add_post_meta($id, "test", "testval"); add_post_meta($id, "testarray", "first"); add_post_meta($id, "testarray", "second"); $a = PostSyncer::getStructuredPostMeta($id); $this->assertEquals($a, array(array("key" => "test", "value" => "testval"), array("key" => "testarray", "value" => "first"), array("key" => "testarray", "value" => "second"))); PostSyncer::setPostMeta($id, array(array("key" => "testarray", "value" => "first"), array("key" => "test", "value" => "testval"), array("key" => "test", "value" => "another test val"), array("key" => "new", "value" => "newval"))); $a = PostSyncer::getStructuredPostMeta($id); $this->assertEquals($a, array(array("key" => "new", "value" => "newval"), array("key" => "test", "value" => "another test val"), array("key" => "test", "value" => "testval"), array("key" => "testarray", "value" => "first"))); }
/** * Get post by local id. */ public function getResource($slug) { $localId = $this->getIdBySlug($slug); $post = get_post($localId); if (!$post) { return NULL; } if ($post->post_status == "trash" || $post->post_status == "inherit") { return NULL; } $parentSlug = $this->getSlugById($post->post_parent); if (!$parentSlug) { $parentSlug = ""; } $data = array("post_name" => $post->post_name, "post_title" => $post->post_title, "post_type" => $post->post_type, "post_content" => $post->post_content, "post_excerpt" => $post->post_excerpt, "post_status" => $post->post_status, "post_parent" => $parentSlug, "menu_order" => $post->menu_order, "meta" => PostSyncer::getStructuredPostMeta($localId)); return $data; }