I have stored URLs in post meta for a custom post type. I need to create a page that lists the download links.

When someone clicks on a download link they should be redirected to the corresponding download page, such as example.com/download.php and after 5 seconds, the downloading of the file (identified by the link stored in post meta) should start automatically

If you need demo to see please see apkpure.com or getintopc.com. When downloading a file, it goes to getintopc.com/getsoft.php, then the download starts.


Finally I solve the problem. Here the code bellow for download button. Put this code into your post loop it will show a download button.

     <form action="<?php echo esc_url( home_url( '/your_redirected_page_slug' ) ); ?>" method="GET" id="form1">
    <?php  global $post;

    <input id="myButton" type="submit" name="a" value="Download" class="single-download-button" />
     <input type="hidden" name="appk" id="mkval" value="<?php echo get_the_ID(); ?>" />                                                  

When someone click on that button it will redirect to download page. Then put the code bellow to that page:

$id = $_GET['appk']; // get form data 
$popularpost = new WP_Query( array('post_type' => 'your_cusom_post_name',
     'posts_per_page' => 9, 
     // 'meta_key' => 'wpb_post_views_count', 
     //'orderby' => 'meta_value_num',                               
     'order' => 'DESC',
     'p' => $id, 
      ) );

    while ( $popularpost->have_posts() ) : $popularpost->the_post();
    $id = get_the_ID();


    <!-- Your Code Function here -->

    // Reset Post Data

Thats it...... enjoy

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.