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
<?php
add_filter('request', 'hwk_post_type_toplevel_request', 1, 1);
function hwk_post_type_toplevel_request($query){
$post_type = 'portfolio';
if(isset($query[$post_type]) && isset($query['post_type']) && $query['post_type'] === 'portfolio')
return $query;
@dgoze
dgoze / get_field_from_block.php
Created August 2, 2024 00:02 — forked from yesnosurely/get_field_from_block.php
get acf field from gutenberg block [php, wp, acf, wordpress]
<?php
function get_field_from_block($post_id, $block_name, $field_name){
$block_name = 'acf/' . $block_name;
$post = get_post($post_id);
if ( has_blocks( $post->post_content ) ) {
$blocks = parse_blocks( $post->post_content );
foreach ($blocks as $block){
if ($block['attrs']['name'] == $block_name){
$data = $block['attrs']['data'][$field_name];
break;
@dgoze
dgoze / image_bg_color_nav_menu_item_ACF.php
Created August 1, 2024 23:48 — forked from vovadocent/image_bg_color_nav_menu_item_ACF.php
Add background-image or background-color to nav menu item using ACF
<?php
//add background-image or background-color to nav menu item using ACF
add_filter('wp_nav_menu_items', 'new_nav_menu_items', 10, 2);
function new_nav_menu_items($items, $args) {
preg_match_all('/menu-item-([0-9]{1,10})"/ ', $items, $matches);
if (isset($matches[0]) && isset($matches[1])) {
foreach ($matches[0] as $k => $repl) {
$post_id = $matches[1][$k];
@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.