Hi,
copy and paste this code to your functions.php file:
function sp_content_analysis_content($content, $id) {
//$content = default WP editor
//$id = current post ID
//Example to add your custom field to content analysis
$cf = get_post_meta($id, 'my-custom-field', true);
$cf .= get_post_meta($id, 'an-other-custom-field', true);
$content = $content.$cf;
return $content;
}
add_filter('seopress_content_analysis_content', 'sp_content_analysis_content');
Change the key “my-custom-field” by the name of your custom field (in ACF, it’s the second field when you create one).
https://www.seopress.org/support/hooks/filter-the-analyzed-content/
Thank you for your reply!
But do I need to use the “get_post_meta” function with every single custom field that I’m using?
Yes, but you can also make a foreach.
Push all the custom fields names to an array and loop on it.
Hi,
Since this topic was start do you have another solution, sure we can do it but it’s not a viable solution.
thanks
Hi,
you can make a request to load all your custom fields instead of specifying them individually.
But it will a non-sense.
We can’t know which one is relevant or not…
In case of we can make Gutenberg block with ACF all fields in blocks is important.
Which request can I do to load all fields ?
Thanks.
We use this function in SEOPress. I think you can easily adapt it to match your needs:
///////////////////////////////////////////////////////////////////////////////////////////////////
//Get all custom fields (limit: 250)
///////////////////////////////////////////////////////////////////////////////////////////////////
function sp_get_custom_fields() {
$cf_keys = wp_cache_get( 'sp_get_custom_fields' );
if ( false === $cf_keys ) {
global $wpdb;
$limit = (int) apply_filters( 'postmeta_form_limit', 250 );
$cf_keys = $wpdb->get_col( "
SELECT meta_key
FROM $wpdb->postmeta
GROUP BY meta_key
HAVING meta_key NOT LIKE '\_%'
ORDER BY meta_key
LIMIT $limit" );
$cf_keys = apply_filters( 'sp_get_custom_fields', $cf_keys );
if ( $cf_keys ) {
natcasesort( $cf_keys );
};
wp_cache_set( 'sp_get_custom_fields', $cf_keys );
}
return $cf_keys;
}
I renamed the function above to avoid any conflicts with the one used in SEOPress.
Hope it helps!