Hi ericrw,
You may do this by writing some code to filter the title to add your tag; the filter hook is aioseop_title and it gets passed the current title by default. Here’s an example with a custom field named my_tag and a replacement parameter in the title format named %my_tag%:
add_filter('aioseop_title', 'sfwd_custom_title');
function sfwd_custom_title($title) {
global $post;
if ( !empty( $post ) ) {
$my_tag = get_post_meta( $post->ID, "my_tag", true );
if ( !empty( $my_tag ) ) $title = str_replace( "%my_tag%", $my_tag, $title );
}
return $title;
}
Hi i’m trying to do the same, but my custom fields are not stored in the post_meta table but in a separate table called “properties”.
for example, In my single page template i use the following code to retrieve the meta values
$post_id = get_the_ID();
$prop = $wpdb->get_row("SELECT * FROM {$wpdb->prefix}properties WHERE <code>post_id</code> = '$post_id' LIMIT 1",ARRAY_A);
and
echo $prop['city']
to display the meta field “city” for example…
Do you have any idea to make your function working with my custom table ?
thanks a lot.
Hi numero7,
This is fairly straightforward, you’d do that like so (example here is for city, replacement tag is %city% ):
add_filter('aioseop_title', 'sfwd_custom_title');
function sfwd_custom_title($title) {
global $post;
if ( !empty( $post ) ) {
$prop = $wpdb->get_row("SELECT * FROM {$wpdb->prefix}properties WHERE post_id = '{$post->ID}' LIMIT 1",ARRAY_A);
$city = $prop['city'];
if ( !empty( $city ) ) $title = str_replace( "%city%", $city, $title );
}
return $title;
}