Skip to content

Instantly share code, notes, and snippets.

View dgoze's full-sized avatar
💭
I may be slow to respond.

Daniel dgoze

💭
I may be slow to respond.
View GitHub Profile
@dgoze
dgoze / remove-custom-taxonomy-metabox.php
Created July 24, 2024 18:06
Remove Custom Taxonomy Metabox from WP Sidebar #wordpress #cptui
<?php
// example custom post type is "event"
// example custom taxonomy is "events-category"
function remove_default_event_category_metabox() {
remove_meta_box( 'tagsdiv-events-category', 'event', 'side' );
}
add_action( 'admin_menu' , 'remove_default_event_category_metabox' );
@dgoze
dgoze / Move Old Event to Past Event Taxonomy.php
Created July 24, 2024 18:06
Move Old Events to 'Past Event' Taxonomy #wordpress #cron
<?php //for formatting - ignore this line
// Move Old Events to 'Past Event' Taxonomy
add_action( 'hide_old_events', 'run_hide_old_events' );
add_action('admin_init', function() { // check on admin load, could be on init, but seems overkill
if (! wp_next_scheduled ( 'hide_old_events' )) { //see if the event is set
wp_schedule_event( strtotime('tomorrow 12:01am'), 'daily', 'hide_old_events' ); //Schedule it to run at 12:01 am - adjust to your liking
}
@dgoze
dgoze / remove-custom-taxonomy-metaboxes.php
Created July 24, 2024 18:06
Remove All Custom Taxonomy Sidebar Metaboxes #cptui #wordpress
<?php // ignore - for formatting only
// Useful if you are creating custom taxonomines and controlling them with ACF. This will remove all the metaboxes for your custom taxonomies
function edit_taxonomy_args( $args, $tax_slug, $cptui_tax_args ) {
// Set to false for all taxonomies created with CPTUI.
$args['meta_box_cb'] = false;
return $args;
}
add_filter( 'cptui_pre_register_taxonomy', 'edit_taxonomy_args', 10, 3 );
@dgoze
dgoze / URL-Param-Shortcode.php
Created July 24, 2024 18:05
Use the [URLParam param='paramName'] shortcode to display GET parameters from the current URL
<?php // ignore this line - only for formatting
// Use the [URLParam param='paramName'] shortcode to display GET parameters from the current URL
function displayURLparam( $atts ) {
extract( shortcode_atts( array(
'param' => 'param',
), $atts ) );
return esc_attr(esc_html($_GET[$param]));
}

Three options to format US phone numbers

PHP
Using PHP to extract (substr) the phone number into separate parts, inject the separator and reassemble. Output with a shortcode

Loops and Logic
Use Loops and Logic's regex feature using capture groups to extract the parts, then insert separator when reassembling the capture groups before outputting the phone number.

Javascript
If you don't have control over the HTML, you can use JS to extract (slice) the phone number into separate parts, inject the separator and reassemble.

@dgoze
dgoze / custom_taxonomy_term_list.php
Created July 24, 2024 18:04 — forked from JiveDig/custom_taxonomy_term_list.php
Show list of terms from a custom taxonomy linked to their archive pages
<?php
add_action( 'genesis_before_loop', 'spears_do_resource_term_links' );
function spears_do_resource_term_links() {
// Show Custom Taxonomy
$args = array( 'taxonomy' => 'resource_type' );
$terms = get_terms('resource_type', $args);
@dgoze
dgoze / show_post_terms.php
Created July 24, 2024 18:03 — forked from JiveDig/show_post_terms.php
Show post terms with links - get_the_term_list
<?php
$language = wp_get_post_terms($post->ID, 'ft_language');
if( $language ) {
echo get_the_term_list( $post->ID, 'ft_language', '<li><span class="detail">Languages:</span>', ', ', '</li>' );
}
@dgoze
dgoze / acf_front_end_edit.php
Created July 24, 2024 18:03 — forked from JiveDig/acf_front_end_edit.php
ACF front end post editing
<?php
/**
* Check if user is logged in and is post author
* Setup functions for front end post editing
* @author Mike Hemberger
* @link http://thestizmedia.com/front-end-post-editing-with-acf-pro/
* @uses Advanced Custom Fields Pro
* @uses Sidr
*/
@dgoze
dgoze / wp-edit-post-front-end.php
Created July 24, 2024 18:03 — forked from JiveDig/wp-edit-post-front-end.php
Filter WP 'Edit Post' link to go to front end /edit-post/ page with ?post_id=123 query arg to allow editing posts via the front end
<?php
/**
* Filter WP 'Edit Post' link to go to front end /edit-post/ page
*
* @author Mike Hemberger
* @link http://thestizmedia.com/front-end-post-editing-with-caldera-forms/
* @return string url to front end for with query arg source post ID ( ?post_id=123 )
*/
add_filter( 'get_edit_post_link', 'tsm_edit_post_link', 10, 1 );
@dgoze
dgoze / recursive-term-metadata.php
Created July 24, 2024 18:02 — forked from JiveDig/recursive-term-metadata.php
Get the specified metadata value for the term or from one of it's parent terms.
<?php
/**
* Get the specified metadata value for the term or from
* one of it's parent terms.
*
* @param WP_Term $term Term object
* @param string $key The meta key to retrieve.
* @param bool $check_enabled Whether to check if custom archive settings are enabled.
*