• Dear reader(s),

    I am quite new to WordPress (2 days) and i’m already bashing my head with the following problem.

    I want to create a simple search / option list on my home page where people can search and download various of data from the database.
    This data is being uploaded to the database with the WordPress File Upload plugin (and it works, i actually see my PDF documents being add in the database).

    Though i have no clue how i can create a search / selection menu in which people can search for the uploaded documents by (for example) name, document type, etc. The kind of documents that are uploaded are mostly pdf and word documents.

    So my question is: how can i create a search / selection menu in which people can specify there search and download the documents that are uploaded / stored in the database? I already try’d it with the default wordpress search but this didn’t seem to work.

    Any suggestions for plugins are fine to! (although i already searched for more than 3 hours for these kind of plugins).

    Thanks in advance!

Viewing 1 replies (of 1 total)
  • Lee

    (@romanempiredesign)

    First of all, why do you need a plugin to upload PDFs to WordPress? You can do this through the media library.

    Second, search comes built into wordpress. Use <?php include(‘searchform.php’); ?>
    in your template to get the searchform.php page that comes in your install.

    What I would do if I were you is set up those pdfs to be added as posts. Then you can give them titles, custom fields, categories and all kinds of good stuff to sort them, link them and download them.

    Something like this should work for you:

    <?php
    $pdfList = "";
    $pdfOutput = "";
    $customfield = "";
    $path = "/wp-content/themes/yourtheme/downloads/";
    $pdf_links = array();
    $pdfList = get_posts( array(
    		'category'		  => '2',
    		'orderby'        => 'title',
    		'order'          => 'ASC',
    		'posts_per_page' => '-1'
    		));
    
    	foreach ( $pdfList as $pdf ) {
    		$customField = get_post_custom($pdf->ID);
    		$pdf_link = $customField['pdf_link'];
    
    	foreach ($pdf_link as $key => $value) {
    		$pdf_links[] = $value;
    	}
    		$pdfOutput .= sprintf( '<a class="pdf-download" href="'. $path .'%s" target="_blank"><img src="'.$path.'/icons/pdf.png" alt="Download" />%s</a>', $value, $pdf->post_title);
    
    }
    echo $pdfOutput;
    ?>

    That will output all your PDF uploads to a page where people can download them.
    You can then use get_post options to sort them or whatever you need to do.

    If you use that code, you’d add a custom field to the post called pdf_link and then add the URL of the PDF you uploaded via the media library.

    That’s how I would do this anyways.

Viewing 1 replies (of 1 total)
  • The topic ‘Creating a selection list to find data in a database’ is closed to new replies.