Skip to content

Commit

Permalink
Return messages if no section ID is set for the articles block
Browse files Browse the repository at this point in the history
  • Loading branch information
ajaydsouza committed Dec 19, 2024
1 parent a702252 commit ee53266
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion includes/blocks/build/sections/index.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-i18n', 'wp-server-side-render'), 'version' => '8dcdb4c49c5937146313');
<?php return array('dependencies' => array('react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-i18n', 'wp-server-side-render'), 'version' => '57b585f3747e128385c5');
2 changes: 1 addition & 1 deletion includes/blocks/build/sections/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions includes/blocks/class-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,13 @@ public function render_articles_block( $attributes ) {
$show_excerpt = isset( $attributes['show_excerpt'] ) ? (bool) $attributes['show_excerpt'] : false;

if ( empty( $attributes['term_id'] ) ) {
return '';
return __( 'Enter a section ID.', 'knowledgebase' );
}

$term = get_term( (int) $attributes['term_id'], 'wzkb_category' );

if ( empty( $term ) || is_wp_error( $term ) ) {
return '';
return __( 'Section not found.', 'knowledgebase' );
}

$list_of_posts = Display::get_posts_by_term(
Expand Down
5 changes: 4 additions & 1 deletion includes/blocks/src/sections/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ export default function Edit({ attributes, setAttributes }) {
const blockProps = useBlockProps();

const { terms, hasResolved, error } = useSelect((select) => {
const query = { per_page: -1 };
const query = {
per_page: -1,
hide_empty: 1,
};
const selectorArgs = ['taxonomy', 'wzkb_category', query];

try {
Expand Down

0 comments on commit ee53266

Please sign in to comment.