• Hello,

    I’m using the pro version of your plugin to import custom fields into a custom database table. I read your tutorial -> https://www.wpallimport.com/documentation/code-snippets/#import-data-to-custom-database-table-during-record-import and it worked well.

    But now a strange problem has occurred. I have a custom post type “person” and a custom taxonomy “height”. The URL looks like this: https://example.com/height/185-cm/

    I would like to filter the output of the taxonomy into male and female persons. The URL then looks like this:
    https://example.com/height/185-cm/?g=male

    For this I use the WordPress hook ‘posts_where’. This is my code:

    // associate the custom table "mytable" with the custom taxonomy
    add_filter('posts_join','custom_join');
    function custom_join($join){
    global $wpdb;
    $customTable = $wpdb->prefix."mytable";
    if (is_tax('height')) {
    $join .= "LEFT JOIN $customTable ON $wpdb->posts.ID = $customTable.post_id";
    }
    return $join;
    }
    
    // filter the male persons from the output list
    add_filter('posts_where', 'male', 1, 2);
    function male( $where )
    {
    if (isset($_GET['g'])) {
    if ($_GET['g'] === 'male') {
    global $wpdb;
    $where .= " AND gender = 'He' ";
    }
    }
    return $where;
    }

    The output is correctly filtered, only male persons are displayed. However, the custom fields from my custom table are no longer displayed in the taxonomy output, although they are existing in the custom table. By the way, I’m using another plugin to manage the custom fields in the custom table: https://www.ads-software.com/plugins/acf-to-custom-database-tables. I had previously tried another plugin, but with the same result.
    Query Monitor shows me that this plugin is not loaded at all in the URL with the parameter.

    I then noticed, that the custom fields in the taxonomy output list reappear again after saving the posts! That means, after a fresh import with WP All Import the custom fields aren’t displayed, but only after saving again the post! It’s very strange, that the custom fields are displayed, when I call the taxonomy list without parameter in the URL. What could be the reason for that?

    I would be very glad, if anyone could help me.

    Thank you very much in advance!
    Andreas

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter Andreas 2013

    (@andreas-2013)

    Sorry, but I have to correct my statements!
    To test whether the error is really due to the parameter, I’ve deleted the if-condition of my code:

    if (isset($_GET['g'])) {
    if ($_GET['g'] === 'male') {

    If I now call https://example.com/height/185-cm/, no custom fields are loaded either!
    They are only loaded, when I’m not using the ‘posts_where’-hook (or if so, after saving post).

    What could that mean?

    • This reply was modified 1 year, 10 months ago by Andreas 2013.
    Thread Starter Andreas 2013

    (@andreas-2013)

    UPDATE:
    The taxonomy doesn’t read from the custom table, but from the wp_postmeta! The single post, on the other hand, correctly displays the custom fields from the custom table!

    Thread Starter Andreas 2013

    (@andreas-2013)

    UPDATE 2:
    The taxonomy READS from the custom table, but only without the ‘posts_where’-hook! With ‘posts_where’-hook the plugin for the custom-table isn’t loaded!

    • This reply was modified 1 year, 10 months ago by Andreas 2013.
    Thread Starter Andreas 2013

    (@andreas-2013)

    I’m currently in contact with the plugin developer and will report a solution as soon as possible…

    Plugin Author WP All Import

    (@wpallimport)

    Hey @andreas-2013,

    Unfortunately, we wouldn’t be able to help troubleshoot a custom workaround like this.

    That said, we can leave this thread open for a bit in case anyone is willing/able to help out.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Custom fields only displayed after saving post’ is closed to new replies.