Issue loading CPT Category Name
-
Hi there everyone! Have not used Genesis for years, but I am back and I was working with Genesis Pro Custom Blocks and a CPT following this Studio Press’s blog post . Made:
<?php /** * Events CPT Block * **/ // Create id attribute allowing for custom "anchor" value. // $id = 'pm-' . $block['id']; // if( !empty($block['anchor']) ) { // $id = $block['anchor']; // } // Create class attribute allowing for custom "className" and "align" values. $className = 'block-events '; if( !empty($block['className']) ) { $className .= ' ' . $block['className']; } if( !empty($block['align']) ) { $className .= ' align' . $block['align']; } // Variables $number_of_events = block_value( 'number-of-events' ); $category = block_value( 'event-category' ); // The Query $the_query = new WP_Query( array( 'post_type' => 'event', 'posts_per_page' => $number_of_events, 'category_name' => $category->name ) ); // The Loop if ($the_query->have_posts()) { echo '<div class="dh-events alignwide">'; while ($the_query->have_posts()) { $the_query->the_post(); // Variables $categories = get_the_category(); $first_cat = $categories[0]->name; $first_cat_url = get_category_link( $categories[0]->term_id ); ?> <div class="dh-events__tile"> <div class="dh-game-event__image" style="background-image: url('<?php echo get_the_post_thumbnail_url(); ?>');"> <a class="dh-event__cat" href="<?php echo $first_cat_url ?>"><?php echo $first_cat; ?></a> </div> <div class="dh-event__tile-content"> <h4><?php the_title(); ?></h4> <?php the_excerpt(); ?> <div class="dh-event__event-author"> <img class="dh-event__avatar" src="<?php echo get_avatar_url( get_the_author_meta( 'ID' )); ?>" alt=""> <span><?php the_author(); ?></span> </div> <a class="dh-event__button" href="<?php the_permalink(); ?>">Read Event</a> </div> </div> <?php } echo '</div>'; } else { // no posts found } /* Restore original Post Data */ wp_reset_postdata(); ?>so far but having
Warning: Undefined property: WP_Error::$name in /Users/jasper/code/site-in-progress/wp-content/themes/theme-in-progress/blocks/dynamic-events/block.php on line 30 Warning: Undefined array key 0 in /Users/jasper/code/site-in-progress/wp-content/themes/theme-in-progress/blocks/dynamic-events/block.php on line 42Any ideas why the category name is not being found? I selected a category for the block in the editor.. here the json:
{ "genesis-custom-blocks\/dynamic-events": { "name": "dynamic-events", "title": "Dynamic Events", "excluded": [ "post", "cheat-sheets", "sponsors", "event" ], "icon": "notifications", "category": { "icon": null, "slug": "theme", "title": "Theme" }, "keywords": [], "fields": { "number-of-events": { "location": "editor", "width": "100", "help": "", "min": 0, "max": 100, "step": 1, "default": "", "name": "number-of-events", "label": "Number of Events", "order": 0, "control": "range", "type": "integer" }, "event-category": { "location": "editor", "width": "100", "help": "", "post_type_rest_slug": "event_category", "name": "event-category", "label": "Event Category", "order": 1, "control": "taxonomy", "type": "object" } } } }and then used the code as shown in
block.phpAnyone seeing what I am missing?The page I need help with: [log in to see the link]
Viewing 7 replies - 1 through 7 (of 7 total)
Viewing 7 replies - 1 through 7 (of 7 total)
The topic ‘Issue loading CPT Category Name’ is closed to new replies.