Skip to content

Instantly share code, notes, and snippets.

View dankoch-cz's full-sized avatar

Daniel Koch dankoch-cz

View GitHub Profile
@dankoch-cz
dankoch-cz / log.php
Created October 16, 2022 21:16
WordPress easy theme log
<?php
/**
* Function to log filters, actions and other parts of the website, that are processed in backend
* Usage theme_log('Log me');
*
* @param (array|string) $log
* @return false
*/
function vk_theme_log($log)
{
@dankoch-cz
dankoch-cz / save_post.php
Last active June 19, 2022 14:43
ACF check old custom field value and compare to new value
<?php
//Documentation: https://www.advancedcustomfields.com/resources/acf-save_post/
add_action('acf/save_post', 'vk_acf_save_post', 5);
function vk_acf_save_post( $post_id ) {
//Bail if post type is not equal "tickets"
if ( get_post_type( $post_id ) != 'tickets' ) {
return;
}
@dankoch-cz
dankoch-cz / functions.php
Created March 9, 2022 15:50
WP shortcode for listing pages
<?php
function list_pages_func( $atts ) {
$a = shortcode_atts( array(
'type' => 'pages',
'id' => '',
), $atts );
$args = array(
'post_type' => $a['pages'],
@dankoch-cz
dankoch-cz / read_csv.php
Created February 23, 2022 09:16
Read CSV file and return array with headers
<?php
function read_csv($file_path,$delimiter) {
$csv_rows = array();
$fp = fopen($file_path, 'r');
$head = fgetcsv($fp, 4096, $delimiter, '"');
// Rows
while($column = fgetcsv($fp, 4096, $delimiter, '"'))
@dankoch-cz
dankoch-cz / rewrite.php
Created February 19, 2022 14:23
Rewrite rules for query vars
<?php
//In functions
add_action( 'init', 'rewrite_plays_url' );
function rewrite_plays_url() {
add_rewrite_rule( 'program/([^/]+)/([^/]+)/([^/]+)?$','index.php?page_id=1&rok=$matches[1]&mesic=$matches[2]&misto=$matches[3]', 'top' );
add_rewrite_rule( 'program/([^/]+)/([^/]+)?$','index.php?page_id=1&rok=$matches[1]&mesic=$matches[2]', 'top' );
add_rewrite_rule( 'program/([^/]+)?$','index.php?page_id=1&rok=$matches[1]', 'top' );
}
add_filter( 'query_vars', 'register_custom_query_vars', 1 );
@dankoch-cz
dankoch-cz / search-db.php
Created November 24, 2021 12:02
Search DB for posts including protected files
<?php
/*
* Query that search wp_posts table for title with defined cpt, taxonomy and taxonomy term ID
*/
global $wpdb;
$table_name = "{$wpdb->prefix}posts";
//Define post type
$post_type = "cpt";
//Define taxonomy and term_ID