php - How do I get data from my database into my Custom Export Field

admin2025-01-07  7

I am trying to get data from my database to export to a XML or CSV File by using a custom query. This is my function with the query :

<?php
function get_workhours($ID){
    $sql = $wpdb->prepare("SELECT worked_hours FROM db_info WHERE job_id = $ID");
    $data = $wpdb->query($sql);
    if(empty($data)){
        return "0";
    }else{
        return $data;
} ?>

And in my custom export field i have this :

[get_workhours{ID}]

And when I try to preview this it gives me the error :

An unknown error occured.

Suggestions for a better idea for this problem are very welcome aswell.

Thanks in advance,

EDIT : I am using the WP All Export Pro Plugin. When adding a field to export I choose the option : Custom export field.

I am trying to get data from my database to export to a XML or CSV File by using a custom query. This is my function with the query :

<?php
function get_workhours($ID){
    $sql = $wpdb->prepare("SELECT worked_hours FROM db_info WHERE job_id = $ID");
    $data = $wpdb->query($sql);
    if(empty($data)){
        return "0";
    }else{
        return $data;
} ?>

And in my custom export field i have this :

[get_workhours{ID}]

And when I try to preview this it gives me the error :

An unknown error occured.

Suggestions for a better idea for this problem are very welcome aswell.

Thanks in advance,

EDIT : I am using the WP All Export Pro Plugin. When adding a field to export I choose the option : Custom export field.

Share Improve this question edited Mar 6, 2019 at 13:42 butlerblog 5,0713 gold badges26 silver badges42 bronze badges asked Mar 6, 2019 at 9:50 TerribleADCTerribleADC 11 bronze badge 1
  • 1 What is 'custom export field'? – Max Yudin Commented Mar 6, 2019 at 10:06
Add a comment  | 

1 Answer 1

Reset to default 0

I think your syntax is wrong. It should be [get_workhours({ID})]. Also press "Save Functions" button before previewing.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736259526a594.html

最新回复(0)