PHP code example of elcontraption / wp-post-inspector
1. Go to this page and download the library: Download elcontraption/wp-post-inspector library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
elcontraption / wp-post-inspector example snippets
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');
$currentPost->ancestors();
$currentPost->descendants();
$currentPost->parent();
$currentPost->permalink();
$currentPost->siblings();
$currentPost->top();
// 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!"
// 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();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.