Related Posts

Ultimate Addons for Elementor causing infinite loading in Elementor
Disable auto-update Email Notifications causing critical errors

PHP Tips & Examples

‘ ‘ used to echo phrases

. to concatenate

$[term] to define a variable

echo to display content

$post (WP_Post) The post object for the current post.

$authordata (WP_User) The author object for the current post

Define current user information

				
					<?php $current_user = wp_get_current_user(); ?>

<?php $current_user_id = get_current_user_id(); ?>
				
			

Display all user data

				
					<?php

$current_user = wp_get_current_user();

echo 'Username: '.$current_user->user_login.'<br>';
echo 'Email: '.$current_user->user_email.'<br>';
echo 'First Name: '.$current_user->user_firstname.'<br>';
echo 'Last Name: '.$current_user->user_lastname.'<br>';
echo 'Display Name: '.$current_user->display_name.'<br>';
echo 'User ID: '.$current_user->ID.'<br>';

?>
				
			

Basic ACF PHP Functions

				
					get_field() // Returns the value of a specific field.
get_field_object() // Returns the settings of a specific field.
get_field_objects() // Returns the settings of all fields saved on a specific post.
get_fields() // Returns an array of field values (name => value) for a specific post.
the_field() // Displays the value of a specific field.
				
			

Add PHP Custom Post Types

				
					// Register Post Types

$init->registerPostTypes([
	'people' => [
		'plural'    => 'People',
		'singular'  => 'Person',
		'supports'  => ['title', 'editor', 'excerpt'],
		'permaLink' => 'leaders/board/{slug}',
		'public'    => true
	],
	'media' => [
		'plural'    => 'Media Posts',
		'singular'  => 'Media Post',
		'supports'  => ['title', 'editor', 'excerpt'],
		'permaLink' => 'media/the-front/{slug}',
		'public'    => true
	],
	'publication' => [
		'plural'    => 'Publications',
		'singular'  => 'Publication',
		'supports'  => ['title', 'excerpt'],
		'permaLink' => 'publications/category/{slug}',
		'public'    => true
	],
	'tmg_update' => [
		'plural'   => 'TMG Updates',
		'singular' => 'TMG Update',
		'supports' => ['title', 'editor'],
		'public'   => false,
		'search'   => false
	],
	'tmg_contact' => [
		'plural'   => 'TMG Contacts',
		'singular' => 'TMG Contact',
		'supports' => ['title'],
		'public'   => false,
		'search'   => false
	],
	'tmg_toolbox' => [
		'plural'   => 'TMG Toolbox',
		'singular' => 'TMG Toolbox',
		'supports' => ['title'],
		'public'   => false,
		'search'   => false
	],
	'tmg_media' => [
		'plural'    => 'TMG Media',
		'singular'  => 'TMG Media',
		'supports'  => ['title', 'editor'],
		'public'   => true,
		'permaLink' => 'account/media/{slug}',
		'search'   => false
	],
	'quote' => [
		'plural'    => 'Quotes',
		'singular'  => 'Quote',
		'supports'  => ['title'],
		'public'    => false,
		'search'    => false
	],
]);