Hello,
I need help on 2 subjects:
1 - I am trying to build a custom query with native wordpress fonctions but it doesn't work. Here is my code:
i am getting the values from to query string
if($_GET['searchcentre'] && !empty($_GET['searchcentre']))
{
$searchcentre = $_GET['searchcentre'];
}
For the query i have this:
<?php
$args = array(
'post_type' => 'projet',
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => 'searchcenter',
'value' => $searchcentre,
'compare' => '='
)
)
);
$query = new WP_Query($args);
?>
In the query i have 12 meta query arrays but i just took this to simplify.
It looks correct by doesn't work at all.
2. And for the second subject, i have 2 post-types (Projet and Centre) and they are related with many to many relation.
The "Projet" post-type has a field "centre" with the name of a centre from the "Centre" post-type and i would like to know how can i get the address of the centre in the "Projet" post-type from the "Centre post-type"?
Thank's for your help, i am new to this and my english is not great.
Thank you
1 - I am trying to build a custom query with native wordpress fonctions but it doesn't work.
Is "searchcenter" a field created in Toolset Types? If so, then you should use the "wpcf-" prefix. If the slug in wp-admin is "searchcenter", then it will look like this:
'key' => 'wpcf-searchcenter',
The "Projet" post-type has a field "centre" with the name of a centre from the "Centre" post-type and i would like to know how can i get the address of the centre in the "Projet" post-type from the "Centre post-type"?
In a Content Template, you can use the Fields and Views button to insert the centre address field. Then use the "Post Selection" tab to select a related post: https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/
In PHP, you must use the Post Relationships API to get the related post ID. Then you can use types_render_field to render the field, or you can use get_post_meta to display the raw data from the database.
To get a related post ID:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts
To display a custom field using types_render_field and the "item" attribute:
https://toolset.com/documentation/customizing-sites-using-php/functions/
Click "+More info" beneath any field type to see examples.
My issue is resolved now. Thank you!