Skip to content

Instantly share code, notes, and snippets.

@vc27
Last active December 15, 2015 01:39
Show Gist options
  • Save vc27/5181555 to your computer and use it in GitHub Desktop.
Save vc27/5181555 to your computer and use it in GitHub Desktop.
The purpose of this class is to append custom field values to the post object. Using this method will lessen the amount of code needed with in "the loop". Rather than writing code with "the loop" you may utilize this class and it's filter to append items to the post object for usage like the following.

AppendPostData

https://github.com/vc27/AppendPostData/

Info

The purpose of this class is to append custom field values to the post object. Using this method will lessen the amount of code needed with in "the loop". Rather than writing code with "the loop" you may utilize this class and it's filter to append items to the post object for usage like the following.

Helper Function


	
	// Options Array
	$option = array(
		'post_type' => array( 'post' ), // Array of post_types
		'custom_fields' => array( // array of post_meta fields
			array(
				'meta_key' => 'some_customfield_name',
				'unique' => 1,
				),
			array(
				'meta_key' => 'another_awesome_customfield',
				'unique' => 1,
				),
			),
		);
	
	
	// Helper Function usage
	append__post_data( $option );
	
	
	/**
	 * $post usage
	 * You would now have access to the following values with in the post object.
	 **/
	$post->some_customfield_name; 
	$post->another_awesome_customfield;
	

Class Usage


	
	// Options Array
	$option = array(
		'post_type' => array( 'post' ), // Array of post_types
		'custom_fields' => array( // array of post_meta fields
			array(
				'meta_key' => 'some_customfield_name',
				'unique' => 1,
				),
			array(
				'meta_key' => 'another_awesome_customfield',
				'unique' => 1,
				),
			),
		);
	
	
	// Class Usage
	$AppendPostData = new AppendPostData();
	$AppendPostData->init( $options );
	
	
	/**
	 * $post usage
	 * You would now have access to the following values with in the post object.
	 **/
	$post->some_customfield_name; 
	$post->another_awesome_customfield;
	
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment