PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, May 15, 2022

[FIXED] how to youtube api data to print in toolset metabox using a button click before save-post

 May 15, 2022     buttonclick, devtoolset, meta-boxes, php, wordpress     No comments   

Issue

i create a metabox with 'import' button in post.php. Also, ready for youtube api data code. but i need, 'when i click 'import' button to run youtube api data function and the values are print in toolset custom fields metabox before i publish or draft the post. after, i check the data is correct then will publish the post in wordpress php.

function add_your_meta_box()
    {
    
    add_meta_box('import-data', 'YT Import', 'function_of_metabox', 'movie', 'side', 'high');
    }
    
    add_action('add_meta_boxes', 'add_your_meta_box'); 
    
    function function_of_metabox()
    {?>
        <input type="submit" class="button button-primary button-large" value="Import" id="Import"/>
    <?php }

button meta box

    function my_add_custom_fields1(){
$post_id = get_the_ID();   
$meta2 = get_post_status($post_id);
$meta3 =   get_post_type( $post_id );
$meta1 = get_post_meta(get_the_ID(), 'wpcf-song-duration', true);  
$ytURL = get_post_meta(get_the_ID(), 'wpcf-song-av', true);
// video id from url
$YouTubeCheck = preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $ytURL, $Data);
    If($YouTubeCheck){
        $youtube_id1 = $Data[1];
    }
    // video json data
$dur1 = file_get_contents("https://www.googleapis.com/youtube/v3/videos?part=contentDetails&id=$youtube_id1&key=AIzaSyAbFclaJBklZ53t_UD-Xz85FbWsfD37sX0");
$duration_key1 = json_decode($dur1, true);
$duration1 = $duration_key1['items'][0]['contentDetails']['duration'];
$start = new DateTime('@0');
$start->add(new DateInterval($duration1));
$h11 = $start->format('H:i:s');
// print the value toolset meta box using print_r $h11;
}
print value toolset custom field meta box 
[toolset custom field meta box][2]

Solution

i find the solution of my coding

<script>
    jQuery('.Import').live('click', function(e) {
        e.preventDefault();
        jQuery('#save').click();
    });
              
    </script>

add the jquery script in same file.

$ytURL = get_post_meta(get_the_ID(), 'wpcf-song-av', true);

change to

$ytURL = $_POST['ytext'];

add text field

<input id="textbox_id" name="ytext" placeholder="YT ID here" type="text" />
<input type="submit"  name="Import" class="Import" id="Import"  />


Answered By - mrpuyal
Answer Checked By - Cary Denson (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing