Skip to content

Instantly share code, notes, and snippets.

View Inzman's full-sized avatar

Indrek Palm Inzman

  • Tartu, Estonia
View GitHub Profile
@Inzman
Inzman / gist:fdd709601b7f93a1b2a6576980bc8916
Last active April 5, 2018 08:23
Fix Wordpress slugs to match their titles
<?php
if(is_user_logged_in()){
$args = array(
'sort_order' => 'asc',
'sort_column' => 'post_title',
'post_type' => 'page',
'numberposts' => -1,
'post_status' => 'publish',
'suppress_filters' => false
);
@Inzman
Inzman / gist:37e64ea7d42a3dd13c18a180577b41b3
Created April 5, 2018 10:03
Update WPML translated pages with original language content
<?php
if(is_user_logged_in()){
$args = array(
'sort_order' => 'asc',
'sort_column' => 'post_title',
'post_type' => 'page',
'numberposts' => -1,
'post_status' => 'publish',
'suppress_filters' => false
);
foreach (array_chunk($users_kicks, 4, true) as $array) {
echo '<div>';
foreach($array as $kicks) {
echo $kicks->brand;
}
echo '</div>';
}
$tax = 'music';
$oterm = 'pop';
$term = get_term_by('slug', $oterm, $tax);
$termChildren = get_term_children($term->term_id, $tax);
$wp_query = new WP_Query();
$wp_query->query(
array(
'posts_per_page' => '5',
'tax_query' => array(
array(
@Inzman
Inzman / gist:e6dd62c3e9dfa6668afeb1128a48f9ea
Created April 19, 2018 07:46
If page slug contains a number
<?php
if(is_user_logged_in()){
$args = array(
'sort_order' => 'asc',
'sort_column' => 'post_title',
'post_type' => 'page',
'numberposts' => -1,
'post_status' => 'publish',
'suppress_filters' => false
);
<?php
if(is_user_logged_in()){
$args = array(
'sort_order' => 'asc',
'sort_column' => 'post_title',
'post_type' => 'page',
'numberposts' => -1,
'post_status' => 'any',
'suppress_filters' => true
);
@Inzman
Inzman / gist:e6b52081bcf612182864b3b7b930724d
Created July 2, 2018 14:06
Write to daily log in Wordpress
if(!function_exists('write_log')){
function write_log($log){
//if(true === WP_DEBUG){
$log_file_name = WP_CONTENT_DIR.'/logs/'.date('Y-m-d').'.log';
if(is_writable($log_file_name)){
if(is_array($log) || is_object($log)){
error_log(print_r($log, true)."\n", 3, $log_file_name);
} else {
error_log($log."\n", 3, $log_file_name);
}
<?php
$a = Array(
1 => Array(
'name' => 'Peter',
'age' => 17
),
0 => Array(
'name' => 'Nina',
'age' => 21
),
@Inzman
Inzman / gist:e9806e9376bf59ebdb49c8d2f9af28a2
Created August 1, 2018 09:08
How to get the tag's slug on the tag page
<?php
$tag = get_queried_object();
echo $tag->slug
?>
@Inzman
Inzman / gist:25ae694d518829296cd4e54a7e93c5f9
Created August 1, 2018 09:09
Allow HTML in WordPress Category & Taxonomy Descriptions
// https://docs.appthemes.com/tutorials/allow-html-in-wordpress-category-taxonomy-descriptions/
// allow html in category and taxonomy descriptions
remove_filter( 'pre_term_description', 'wp_filter_kses' );
remove_filter( 'pre_link_description', 'wp_filter_kses' );
remove_filter( 'pre_link_notes', 'wp_filter_kses' );
remove_filter( 'term_description', 'wp_kses_data' );