Created
February 15, 2011 12:02
-
-
Save hiddentrak/827436 to your computer and use it in GitHub Desktop.
Add Magic Fields support to FlashPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This function returns a Magic Fields group | |
* @param string $name_group The name of the group you are looking for | |
* @param integer $post_id The Wordpress post id | |
*/ | |
public function getMagicFieldsGroup( $name_group, $post_id=NULL ) { | |
$group = get_group( $name_group, $post_id ); | |
$order = get( 'order', 1, 1, true, $post_id ); | |
$g = false; | |
$g -> {'sections'} = array(); | |
foreach( $group as $key => $value ) | |
{ | |
$section = false; | |
foreach( $value as $k => $v ) | |
{ | |
$section -> {$k} = $v[1]; | |
} | |
array_push( $g->sections, $section ); | |
} | |
$g->{'order'} = $order; | |
return $g; | |
} | |
/** | |
* This function returns all posts in a category along with the associated magic fields | |
* @param string $category_name The name of the category you are looking for | |
* @param string $number_posts The maximum number of posts you would like returned | |
* @param string $group_name The name of the magic fields group to retrieve | |
*/ | |
public function getCategoryWithMagicFields( $category_name, $number_posts=10, $group_name=NULL ) | |
{ | |
$args = 'numberposts=' . $number_posts . '&category_name=' . $category_name; | |
$myPosts = get_posts($args); | |
$p = $this->postDataParser($myPosts); | |
$results = array(); | |
foreach( $p as $value) | |
{ | |
$magicFieldsGroup = $this->getMagicFieldsGroup( $group_name, (int)$value->ID ); | |
$magicFieldsGroup->{'title'} = $value->post_title; | |
$magicFieldsGroup->{'name'} = $value->post_name; | |
array_push( $results, $magicFieldsGroup ); | |
} | |
return $results; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment