Skip to content

Instantly share code, notes, and snippets.

@goiblas
Created April 4, 2020 15:46
Show Gist options
  • Save goiblas/3dece79cc3c3683d3779d1896fa4a939 to your computer and use it in GitHub Desktop.
Save goiblas/3dece79cc3c3683d3779d1896fa4a939 to your computer and use it in GitHub Desktop.
<?php
//...
register_block_type( 'block-list-post-type/block-list-post-type', array(
'editor_script' => 'block_list_post_type_scripts',
'render_callback' => 'block_list_post_type_render',
'attributes' => [
// ...
]
) );
}
// ...
function block_list_post_type_render($attributes) {
$args = array(
'post_type' => $attributes['selected'],
'posts_per_page' => 6,
'post_status' => 'publish',
);
$entity = new WP_Query( $args );
$entityList = '';
while( $entity->have_posts() ) :$entity->the_post();
$entityList .= '<li><a href='. get_permalink().'>'. get_the_title() .'</a></li>';
endwhile;
wp_reset_postdata();
return '</ul>'. $entityList . '</ul>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment