Custom fields aren’t loaded when using URL with parameter
-
Hi Abhishek,
I got a problem with your plugin and I hope you can help me.
I have a custom post type “person” and a custom taxonomy “height”. Your plugin works, the custom fields for the people are written correctly in the custom table and are displayed in the output.
The URL looks like this: https://example.com/height/185-cm/Now 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=maleFor 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 “mytable” are no longer loaded in the taxonomy output, although I haven’t changed anything in the template. Query Monitor shows me that the plugin is not loaded at all in the URL with the parameter.
What can the problem be related to?
Thank you for your help in advance!
Andreas
- The topic ‘Custom fields aren’t loaded when using URL with parameter’ is closed to new replies.