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 / custom-post-type-acf-endpoint.php
Created August 1, 2024 23:47 — forked from cpearson3/custom-post-type-acf-endpoint.php
WordPress REST Endpoint for Custom Post Types and ACF
function my_endpoint( $request_data ) {
// setup query argument
$args = array(
'post_type' => 'my_post_type',
);
// get posts
$posts = get_posts($args);
@dgoze
dgoze / template-functions.php (for CPT)
Created August 1, 2024 23:46 — forked from woraperth/template-functions.php (for CPT)
[WordPress] Add ACF Admin Column to Custom Post Type (In this example, CPT name = events & ACF column name = event_date). This also make the column sortable.
// Add ACF Columns
function add_new_events_column($columns) {
$columns['event_date'] = 'Event Date';
return $columns;
}
add_filter('manage_events_posts_columns', 'add_new_events_column');
function add_new_events_admin_column_show_value( $column, $post_id ) {
if ($column == 'event_date') {
@dgoze
dgoze / countdown.php
Created August 1, 2024 23:45 — forked from ferourives/countdown.php
Event countdown WP loop with datepicker ACF
<!-- competitions countdown with post type "competição" -->
<?php
//If the event is happening
$args = array(
'post_type' => 'competicao',
'meta_query' => [
'relation' => 'AND',
[
'key' => 'date_picker',
'compare' => '<=',
@dgoze
dgoze / gist:2b3e51e2c21d38f941e5f1aa34f81c51
Created August 1, 2024 23:44 — forked from fourstacks/gist:9806658
Mega menu using nested ACF repeaters/flex
<?php
// check parent repeater
if( have_rows('parent_navigation_items', 'options') ):
echo '<ul class="nav primary-header-nav">';
// loop parent items
while ( have_rows('parent_navigation_items', 'options') ) : the_row();
echo '<li>';
@dgoze
dgoze / add-help-text.php
Created August 1, 2024 23:43 — forked from danielpataki/add-help-text.php
Simplify the admin
function my_post_guidelines() {
$screen = get_current_screen();
if ( 'post' != $screen->post_type )
return;
$args = array(
'id' => 'my_website_guide',
'title' => 'Content Guidelines',
@dgoze
dgoze / featured image from gallery.php
Created August 1, 2024 23:43 — forked from mattradford/featured image from gallery.php
Set the featured image from the first entry in an ACF gallery field, saving only for a specified post type.
@dgoze
dgoze / timecompare.php
Created July 25, 2024 16:03 — forked from barbwiredmedia/timecompare.php
Wordpress Working with time datepicker in javascript and ACF meta date. Reformat time for use by persons and show different content depending on if the date has passed.
<?php
// http://php.net/manual/en/function.date.php
//get the time from the ACF time picker see php.net for date formats
$printdate = DateTime::createFromFormat('Ymd', get_post_meta($post->ID, 'event_date', 'true')); //event_date from custom feild
$eventDate = $printdate->format('m/d/Y');
if (time() < strtotime("$eventDate 11:59PM")) { ?>
<!-- the date has not passed SHOW CONTENT -->
<?php } else { ?>
<!-- SORRY the date has passed already-->
@dgoze
dgoze / referer.php
Created July 25, 2024 16:03 — forked from barbwiredmedia/referer.php
Checking for page referer in php. Wordpress redirect or header refresh
<?php
//check for refering page to switch content based on referrer
$referrer = $_SERVER['HTTP_REFERER'];
if ($referrer == 'http://url.com' or $referrer == 'http://url-2.com') {
//Matches YES!
} else {
//Matches NO!
header( 'Location: http://www.url.com/no-soup-for-you/' ) ;
@dgoze
dgoze / functions.php
Created July 25, 2024 16:03 — forked from barbwiredmedia/functions.php
Wordpress filter the_excerpt to include page formatting on output, trim excerpt length. From Aaron Russell: http://aaronrussell.co.uk/legacy/improving-wordpress-the_excerpt/
//Excerpt with formating from WYSIWYG
function improved_trim_excerpt($text) {
global $post;
if ( '' == $text ) {
$text = get_the_content('');
$text = apply_filters('the_content', $text);
$text = str_replace('\]\]\>', ']]&gt;', $text);
$text = preg_replace('@<script[^>]*?>.*?</script>@si', '', $text);
//$text = strip_tags($text, '<p>');
$excerpt_length = 70;
@dgoze
dgoze / template.php
Created July 25, 2024 16:03 — forked from barbwiredmedia/template.php
Wordpress: H1 headlines on different pages.Single / singular / archive
<h1>
<?php if (is_singular('your_cpt') || is_archive('your_cpt') || is_post_type_archive('your_cpt') ) { ?>
YOUR CPT NAME
<?php } elseif (is_search()) { ?>
Search
<?php } elseif (is_404()) { ?>
Error 404
<?php } else { ?>
<?php the_field('headline_text'); ?>
<?php } ?>