Title: Reading a CSV file???
Last modified: August 21, 2016

---

# Reading a CSV file???

 *  [dancingbay](https://wordpress.org/support/users/dancingbay/)
 * (@dancingbay)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/reading-a-csv-file/)
 * I use WordPress and Cart66 to run an online store. One of my blanks vendors has
   a CSV online that contains the the SKU, Description, Qty in Stock, and Custom
   Status.
 * I’m interested in pulling out the last 2 fields of the SKU for what ever page
   my customer is on, so that I have an up to date quantity that can be ordered 
   and any information on when out of stock items will be back in stock.
 * I’ve searched all the ways I can think of for a plugin or hack that will do this,
   but so far have only found plugins that make it easier to manually load csv files,
   but not any that will allow the website to directly read/load the csv file from
   a URL.
 * A while back, I wrote a little PHP script that would read a csv file from a URL
   and parse the data, but don’t have a clue how to integrate that into WordPress.
 * Any ideas or advice would be greatly appreciated.
 * Thanks,
    Alisa

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/reading-a-csv-file/#post-4903133)
 * Create a function that will do the work, it can be declared in functions.php 
   of your theme or as a simple plugin. You would call the function from whichever
   templates are to display the data.
 * The function would use `file_get_contents()` or if your server has it installed,
   cURL to get the CSV file. Once you have the file data in PHP, you could use PHP
   string search functions to find the proper line and extract the needed fields.
   It’s also likely there is some sort of library available to handle CSV files 
   just like there are for JSON and XML. Or simply make use of your existing script.
 *  [Rahul Balakrishna](https://wordpress.org/support/users/rahulbalakrishna/)
 * (@rahulbalakrishna)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/reading-a-csv-file/#post-4903173)
 * Firstly you need to add function in functions.php as below
 * In the below code 2 is the number of parameter passed to function and 10 is the
   priority in which the function is going to be executed.
 *     ```
       add_action( 'after_setup_theme', 'your_csv_function_name',10,2 );
   
       function your_csv_function_name(param1, param2) {
       	/* Your code comes here */
       }
       ```
   
 * For information related to add_action visit [here](http://codex.wordpress.org/Function_Reference/add_action)
 * Or you can use Shortcode, to know more about it visit [here](http://codex.wordpress.org/Shortcode_API)

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Reading a CSV file???’ is closed to new replies.

## Tags

 * [csv](https://wordpress.org/support/topic-tag/csv/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 2 replies
 * 3 participants
 * Last reply from: [Rahul Balakrishna](https://wordpress.org/support/users/rahulbalakrishna/)
 * Last activity: [12 years, 3 months ago](https://wordpress.org/support/topic/reading-a-csv-file/#post-4903173)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
