├── LICENSE ├── README.md └── functions.php /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Steven Cotterill 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## WordPress Custom Columns for admin area 2 | 3 | This is an example of how to add custom columns into the WordPress admin area. It allows extra information to be shown on the list pages as seen below: 4 | 5 |  6 | 7 | This is meant to be expanded on / customised to meet the needs of your website. 8 | 9 | View relevant article [here](https://stevencotterill.co.uk/blog/adding-custom-columns-to-the-wordpress-admin-area) -------------------------------------------------------------------------------- /functions.php: -------------------------------------------------------------------------------- 1 | '; 27 | 28 | } 29 | 30 | elseif ($column === 'car_sold_price') { 31 | 32 | $car_sold_price = get_field('car_sold_price'); 33 | 34 | if ($car_sold_price) { 35 | $car_sold_price = number_format($car_sold_price); 36 | echo '£' . $car_sold_price . '
'; 37 | } else { 38 | echo 'For sale'; 39 | } 40 | 41 | } 42 | 43 | elseif ($column === 'car_profit_loss') { 44 | 45 | $car_bought_price = get_field('car_bought_price'); 46 | $car_sold_price = get_field('car_sold_price'); 47 | 48 | if ($car_sold_price) { 49 | 50 | $car_profit_loss = $car_sold_price - $car_bought_price; 51 | 52 | if ($car_profit_loss >= 1000) { 53 | echo '+'; 54 | } else { 55 | echo '
'; 56 | } 57 | 58 | echo $car_profit_loss . '
'; 59 | 60 | } else { 61 | echo 'For sale'; 62 | } 63 | 64 | } 65 | 66 | } 67 | add_action('manage_posts_custom_column' , 'columns_cars_data', 10, 2); ?> --------------------------------------------------------------------------------