Created
August 31, 2020 16:45
-
-
Save boospot/b8d8114c92e2b45200e29b855b51b6cb 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 | |
/* | |
Plugin Name: Post Meta File | |
Plugin URI: | |
Description: | |
Author: | |
Version: | |
Author URI: | |
*/ | |
// Shortcode_display : post_meta_file // like: show_post_list | |
function post_meta_file_cb( $atts = [], $content = null, $tag = '' ) { | |
$loop = get_transient( 'post_meta_files_loop' ); | |
if ( ! $loop ) { | |
$args = array( | |
'post_type' => 'post', | |
'posts_per_page' => - 1, | |
'meta_query' => array( | |
array( | |
'key' => 'test_video', | |
'value' => '', | |
'compare' => '!=', | |
), | |
) | |
); | |
$loop = new WP_Query( $args ); | |
set_transient( 'post_meta_files_loop', $loop, 6 * HOUR_IN_SECONDS ); | |
} | |
ob_start(); | |
if ( $loop->have_posts() ) : | |
echo '<ul>'; | |
while ( $loop->have_posts() ) : $loop->the_post(); | |
$files = get_field( 'test_video' ); | |
?> | |
<li><a href="<?php echo $files['url']; ?>"><?php echo $files['title']; ?></a></li> | |
<?php | |
endwhile; | |
echo '</ul>'; | |
else : | |
_e( 'Sorry, no posts matched your criteria.', '' ); | |
endif; | |
?> | |
<div class=""> | |
</div> | |
<?php | |
// return output | |
return ob_get_clean(); | |
} | |
add_shortcode( 'post_meta_file', 'post_meta_file_cb' ); | |
//add_action( 'save_post', function($post_id, $post, $update){ | |
// | |
// // Check to see if we are autosaving | |
// if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) | |
// return; | |
// | |
// delete_transient( 'post_meta_files_loop'); | |
// | |
//}, 10,3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment