Created
April 4, 2020 15:46
-
-
Save goiblas/3dece79cc3c3683d3779d1896fa4a939 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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