2017 © Pedro Peláez
 

library wp-post-inspector

Tools for interacting and inspecting WordPress post objects.

image

elcontraption/wp-post-inspector

Tools for interacting and inspecting WordPress post objects.

  • Thursday, May 3, 2018
  • by elcontraption
  • Repository
  • 1 Watchers
  • 0 Stars
  • 343 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 8 Versions
  • 0 % Grown

The README.md

WP Post Inspector

Tools for interacting and inspecting WordPress post objects., (*1)

Installation

Install as a dependency of your theme via composer:, (*2)

composer require elcontraption/wp-post-inspector

Retrieving a post object

use \WpPostInspector\PostInspector;

// Get the current post object:
$currentPost = new PostInspector();

// Get a specific post object by ID
$post1 = new PostInspector(1);

// Get a specific post object by slug:
$helloWorldPost = new PostInspector('hello-world');

Methods

ancestors

Returns array of ancestors as PostInspector objects., (*3)

$currentPost->ancestors();

descendants

Returns array of descendants as PostInspector objects., (*4)

$currentPost->descendants();

parent

Access parent PostInspector object., (*5)

$currentPost->parent();

Shortcut for get_permalink($currentPost->id())., (*6)

$currentPost->permalink();

siblings

Returns array of siblings as PostInspector objects., (*7)

$currentPost->siblings();

top

Access the top ancestor as a PostInspector object., (*8)

$currentPost->top();

Accessing post attributes

You may either use standard WP_Post attributes (as methods) or any of the shortcut methods built in to this class., (*9)

// Display the current post title using a shortcut method:
echo $currentPost->title(); // "Hello world!"

// Using a standard WP_Post attribute name:
echo $currentPost->post_title(); // "Hello world!"
Attribute name Shortcut method
ID id
post_author author
post_date date
post_date_gmt gmt or dateGmt
post_content content
post_title title
post_excerpt excerpt
post_status status
comment_status commentStatus
ping_status pingStatus
post_password password
post_name name or slug
to_ping toPing
pinged pinged
post_modified modified
post_modified_gmt modifiedGmt
post_content_filtered contentFiltered
post_parent parent
guid guid
menu_order menuOrder
post_type type
post_mime_type mimeType
comment_count commentCount

filter | filter

Traversing the post hierarchy

You may traverse the post hierarchy using the parent, top, ancestors, descendants, and siblings methods:, (*10)

// Get the parent of the current post object:
$parent = $currentPost->parent();

// Accessing attributes on the parent object:
echo $parent->slug();

// Display the title of the top ancestor post object
echo $currentPost->top()->title();

// The 'ancestors', 'descendants', and 'siblings' methods all return arrays of PostInspector objects:
$ancestors = $currentPost->ancestors();

foreach ($ancestors as $ancestor)
{
    var_dump($ancestor->title());
}

// Method chaining is possible:
$grandParent = $currentPost->parent()->parent();
$grandAunts = $currentPost->parent()->parent()->siblings();

The Versions

03/05 2018

dev-master

9999999-dev

Tools for interacting and inspecting WordPress post objects.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

03/05 2018

0.1.5

0.1.5.0

Tools for interacting and inspecting WordPress post objects.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

03/05 2018

0.1.4

0.1.4.0

Tools for interacting and inspecting WordPress post objects.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

25/09 2015

0.1.3

0.1.3.0

Tools for interacting and inspecting WordPress post objects.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

25/05 2015

0.2.0.x-dev

0.2.0.9999999-dev https://github.com/elcontraption/wp-post-inspector

Tools for interacting and inspecting WordPress post objects.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

18/03 2015

0.1.2

0.1.2.0

Tools for interacting and inspecting WordPress post objects.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

18/03 2015

0.1.1

0.1.1.0

Tools for interacting and inspecting WordPress post objects.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

18/03 2015

0.1.0

0.1.0.0

Tools for interacting and inspecting WordPress post objects.

  Sources   Download

MIT

The Requires

  • php >=5.4.0