Create REST API endpoint for indexables – Yoast SEO in WordPress
-
Has anyone create a REST API endpoint in YOAST SEO. I need to fetch all the data from yoast seo and return as JSON format. Any one who done this please support.
add_action(‘rest_api_init’, function () {
register_rest_route($this->namespace, ‘/get_wpsitemap’, array(
‘methods’ => ‘GET’,
‘callback’ => array($this->plugin_public, ‘yoast_seo_sitemap_cust’),
‘permission_callback’ => ‘__return_true’,
));
});
function yoast_seo_sitemap_cust()
{
global $wpdb;
// $post_ids = get_posts(array(
// ‘fields’ => ‘ids’, // Only get post IDs
// ));
// var_dump($post_ids);$results = $wpdb->get_results(‘SELECT * FROM
xxxx_indexable‘);
foreach ($results as $result) {
//var_dump($result->permalink);$output[] = array(
‘Title’ => $result->breadcrumb_title,
‘permalink’ => $result->permalink,
);
}
return $output;}
Here i used this method to get value from Yoast. I don’t know it is correct method or not. Here i just directly fetch the value from database and add to array. Is this correct method or any other method exit. I need all the yoast data as json format. Please share the code or link.
I don’t have a site linked to this WordPress.com account
-
Hello there,
Many thanks for reaching out.
Are you able to confirm the URL of the website that you need assistance with please?
-
-
Hi,
Is that the correct method to fetch the data from yoast. Because we are using coupled architecture. Frontend we are using NEXTJS, backend wordpress. So we need to sent the yoast data as Json format to Nextjs. Here i used this method. It directly fetch the value from table and assign to array and return the value. And know it is working. But I don’t know , Is it the correct method or not. Using this method is we get all the data or not.
If you know anything about this please support. -
Hi there, That information would help us establish is where your website is hosted. These forums you’ve posted to assist folks whose sites are hosted here, on WordPress.com, the hosting provider.
If you are talking about a site using the open source WordPress software hosted with GoDaddy, SiteGround, Pressable and the like, or using a localhost install, then you’ll want to ask your question about the REST API over here. https://developer.wordpress.org/
In general, questions about the open source WordPress software are best asked in their forums at https://wordpress/org/support/
Hope that helps set you on the right track.
-
Okay, Thank you for support. We don’t know anything about which hosting provide are they using. We have get only this task to complete. thank you .
- The topic ‘Create REST API endpoint for indexables – Yoast SEO in WordPress’ is closed to new replies.