Skip to content

Instantly share code, notes, and snippets.

View tlehtimaki's full-sized avatar

Toni tlehtimaki

  • Vaisala Oyj
  • Helsinki, Finland
View GitHub Profile
@tlehtimaki
tlehtimaki / wp_custom_post_title_filter.php
Last active September 14, 2018 18:45
Build WordPress post_title from post related metadata
<?php
/**
* Assign name as title before save when post type is company_personnel.
*
* Instruction of use:
* ------------------
* you can place this eg. in your themes functions.php
*
* Use case:
* --------
@tlehtimaki
tlehtimaki / pass_var_to_template.php
Created January 4, 2018 08:15
Pass variables to template in WordPress
<?php
public static function get_template($template, $variables = array()) {
// Pass variables as a key-value array: array('varname' => 'varvalue')
// and conditionally check for them in templates like this:
// $varname = !empty($varname) ? $varname : NULL
foreach ($variables as $key => $value) {
// Create variables from parameters
${$key} = $value;
@tlehtimaki
tlehtimaki / page_children.php
Created November 14, 2017 09:01
Get wordpress page children ID's
<?php
// Setup $post
glopal $post;
// Store current post ID
$current_post_id = $post->ID;
// Note the slash here refers to global namespace.
$children = new \WP_Query(
array(
@tlehtimaki
tlehtimaki / reorder_user_table_by_id.php
Last active August 24, 2017 06:08
Reordering WordPress User Table by User ID
<?php
/**
* Reorder WordPress User table by user ID
*
* @param object $query Instance of WP_User_Query
* @return object $query Altered instance of WP_User_Query
*/
function my_custom_order_users_by_id( $query ) {
// Check that we are in admin otherwise return