Skip to content

Instantly share code, notes, and snippets.

@boospot
Created August 31, 2020 16:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save boospot/b8d8114c92e2b45200e29b855b51b6cb to your computer and use it in GitHub Desktop.
Save boospot/b8d8114c92e2b45200e29b855b51b6cb to your computer and use it in GitHub Desktop.
<?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