{"id":16806775,"date":"2023-06-09T13:34:38","date_gmt":"2023-06-09T13:34:38","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/get-focus-keyword-through-wordpress-api-for-a-post\/"},"modified":"2023-06-09T13:34:38","modified_gmt":"2023-06-09T13:34:38","slug":"get-focus-keyword-through-wordpress-api-for-a-post","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/get-focus-keyword-through-wordpress-api-for-a-post\/","title":{"rendered":"Get focus keyword through WordPress API for a post"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Hey there, <\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I&#8217;m trying to retrieve focus keyword from a draft post using wordpress API. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I manage to get the description, title and content but I don&#8217;t knwo why i cannot get the yoast focus Keyword. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Do you have any idea of what I can do ?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">here is a sample of the script I&#8217;m using : <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from wordpress_xmlrpc import Client, WordPressPost\nfrom wordpress_xmlrpc.methods.posts import GetPost\n\n# website connexion\nurl = ''\nusername = ''\npassword = ''\n\n# client\nclient = Client(url, username, password)\n\n# Article ID\npost_id = 12345\n\n# data\npost = client.call(GetPost(post_id))\nprint(post)\n\n# meta\nyoast_title = None\nyoast_description = None\nyoast_keywords = None\n\nfor meta_field in post.custom_fields:\n    if meta_field.keys == '_yoast_wpseo_title':\n        yoast_title = meta_field.value\n    elif meta_field.keys == '_yoast_wpseo_metadesc':\n        yoast_description = meta_field.value\n    elif meta_field.keys == '_yoast_wpseo_focuskw':\n        yoast_keywords = meta_field.value\n\n# display\nprint(\"Titre Yoast:\", yoast_title)\nprint(\"Description Yoast:\", yoast_description)\nprint(\"Mots-cl\u00e9s Yoast:\", yoast_keywords)\n<\/code><\/pre>\n","protected":false},"template":"","class_list":["post-16806775","topic","type-topic","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/16806775","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/16806775\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=16806775"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}