Creating Your Own WordPress Metabox. Attaching a PDF file to an article.
Create your own metabox WordPress, we fix PDF file by article. It is very convenient to use additional fields when developing a plugin. “metabox“.
To get started, you need to download WordPress PDF file. After downloading, open the function.php file and paste the code there:
add_action("admin_init", "pdf_init");
add_action('save_post', 'save_pdf_link');
function pdf_init(){
add_meta_box("my-pdf", "PDF Document", "pdf_link", "post", "normal", "low");
}
function pdf_link(){
global $post;
$custom = get_post_custom($post->ID);
$link = $custom["link"][0];
$count = 0;
echo '';
$query_pdf_args = array(
'post_type' => 'attachment',
'post_mime_type' =>'application/pdf',
'post_status' => 'inherit',
'posts_per_page' => -1,
);
$query_pdf = new WP_Query( $query_pdf_args );
$pdf = array();
echo '
';
echo 'Selecting a pdf file from the above list to attach to this post.
';
echo 'Files: '.$count.'';
}
function save_pdf_link(){
global $post;
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE){ return $post->ID; }
update_post_meta($post->ID, "link", $_POST["link"]);
}
add_action( 'admin_head', 'pdf_css' );
function pdf_css() {
echo '';
}
function pdf_file_url(){
global $wp_query;
$custom = get_post_custom($wp_query->post->ID);
echo $custom['link'][0];
}Next, go to the section for creating a new article and scroll to the bottom of the page. In the metabox that appears, in the drop down list, select the downloaded file.
You can get the address like this:
pdf_file_url(); ?>
An example of using an uploaded file:
My PDF File
Code checked, everything works perfectly. Good luck with development.
/*

- Basic web design course;
- Site layout;
- General course on CMS WordPress and continuation of the course on template development;
- Website development in PHP.




