Home›Support›English Support›[Resolved] WordPress Rest API documentation for Posts, Custom Post, Custom Taxonomy
[Resolved] WordPress Rest API documentation for Posts, Custom Post, Custom Taxonomy
This thread is resolved. Here is a description of the problem and solution.
Problem: The client is building a headless application and needs REST API documentation for handling posts, custom posts, taxonomies, and custom taxonomies with language filtering.
Solution: If you're experiencing this, we recommend using the WordPress REST API to retrieve taxonomy terms. To get the list of terms for a taxonomy, use the following endpoint:
Please note that custom code is beyond our support policy. If you need further assistance with custom code, consider contacting one of our certified partners.
If you want to get the list of terms of taxonomy, you can use this URL: hidden link{taxonomy-slug}
If you want to get the list of terms of taxonomy in a second language, you can use this URL: hidden link{taxonomy-slug}?lang={lang_code}
For example: the list of categories in German language: hidden link
You can test this feature on a sandbox site, here is the URL to access the site directly hidden link
You can follow the WordPress documentation to create a query to get posts from a category. In the loop, use the WPML filter hook "wpml_object_id" to get the translation post ID in a specific language and output post info based on the ID. Here is an example:
$args = array(
'post_type' => 'post',
'tax_query' => array(
array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => 'bob',
),
),
);
// The Query.
$the_query = new WP_Query( $args );
// The Loop.
if ( $the_query->have_posts() ) {
echo '<ul>';
while ( $the_query->have_posts() ) {
$the_query->the_post();
$my_post_id = get_the_ID();
$my_post_id = apply_filters( 'wpml_object_id', $my_post_id, 'post', false, 'fr' ); //get the post ID in French
echo '<li>' . esc_html( get_the_title( $my_post_id ) ) . '</li>';
}
echo '</ul>';
} else {
esc_html_e( 'Sorry, no posts matched your criteria.' );
}
// Restore original Post Data.
wp_reset_postdata();
Note: this is a custom code and I would like to inform you that helping you with custom code, is out of the scope of WPML. If you are not able to accomplish this, I would recommend you contact one of our certified partners who will be more than happy to help you with this. In this link, you will find a list of our certified partners: https://wpml.org/contractors/
I'm afraid that there isn't an argument "lang" to set the language in the list of arguments like that. You can use the filter hook "wpml_object_id" in the loop, as I mentioned above, to get the translation post ID in a specific language.
I have uploaded a test plugin it was somehow cache i believed so and its working now with that hook method. can you guide me how to retrieve a single post based on language??
Please note: this is a custom code and I would like to inform you that helping you with custom code, is out of the scope of WPML. If you cannot accomplish this, I recommend you contact one of our certified partners who will be more than happy to help you with this. In this link, you will find a list of our certified partners: https://wpml.org/contractors/
Thanks.
Manage Cookie Consent
We use cookies to optimize our website and services. Your consent allows us to process data such as browsing behavior. Not consenting may affect some features.
Functional
Always active
Required for our website to operate and communicate correctly.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
We use these to analyze the statistics of our site. Collected information is completely anonymous.The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
These cookies track your browsing to provide ads relevant to you.