Skip to content

Instantly share code, notes, and snippets.

@khoipro
Last active November 1, 2023 12:34
Show Gist options
  • Save khoipro/eb20734828faee2193553e556d02a27f to your computer and use it in GitHub Desktop.
Save khoipro/eb20734828faee2193553e556d02a27f to your computer and use it in GitHub Desktop.
Get Yoast SEO meta by calling a DB
<?php
function get_yoast_seo_category_meta_title( $object_id) {
global $wpdb;
$table_name = $wpdb->prefix . 'yoast_indexable';
$result = $wpdb->get_row( $wpdb->prepare("SELECT title FROM $table_name WHERE `object_id` = '%s' AND `object_sub_type` = 'category';", $object_id), ARRAY_A );
return $result['title'] ?? 'None';
}
function get_yoast_seo_category_meta_desc( $object_id) {
global $wpdb;
$table_name = $wpdb->prefix . 'yoast_indexable';
$result = $wpdb->get_row( $wpdb->prepare("SELECT description FROM $table_name WHERE `object_id` = '%s' AND `object_sub_type` = 'category';", $object_id), ARRAY_A );
return $result['description'] ?? 'None';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment