yi100
Forum Replies Created
Viewing 2 replies - 1 through 2 (of 2 total)
-
Hello. Sorry, I don’t quite understand. My original articles were using the default post type provided by WordPress — I haven’t used any custom types before. So do I need to create a post type called “post” in your plugin?
Is there any detailed documentation available?Thank you.
Thank you very much. However, I would like to add a new variable while retaining the old one, so that both can be used together. I asked ChatGPT to write a piece of code for this, but I’m not sure if it’s correct.
add_action('rank_math/vars/register_extra_replacements', function () {
rank_math_register_var_replacement(
'category_titles',
[
'name' => esc_html__('Category Titles', 'rank-math'),
'description' => esc_html__('Displays the titles of the latest posts in the current category', 'rank-math'),
'variable' => 'category_titles',
'example' => 'Post Title 1, Post Title 2, Post Title 3, ...',
],
'get_category_titles'
);
});
function get_category_titles() {
if (is_category()) {
$cat = get_queried_object_id();
$myposts = get_posts(array(
'numberposts' => 10,
'offset' => 0,
'category__in' => array($cat),
'post_status' => 'publish',
'order' => 'DESC'
));
$titles = [];
foreach ($myposts as $post) {
$titles[] = get_the_title($post->ID);
}
return implode(', ', $titles);
}
return '';
}
Viewing 2 replies - 1 through 2 (of 2 total)