How to use the_post to change post_title?
-
For specific post I want to change post depending of category which is provided as additional parameter.
I tried this:
add_action( 'the_post', 'un_post_filter' ); function un_post_filter ( $post ) { if ($post->post_type == 'page' && $post->post_name == 'mypage') { $category_name = get_query_var ('category_name'); if (! empty ($category_name)) { $category = get_category_by_slug($category_name); $post->post_title .= ": " . $category->name; $post->title = $post->post_title; } }
According to documentation and scarce examples of using action the_post this should change values and changes should be visible in HTML.
Changes on the $post are applied as expected, but HTML still shows unaltered values.
What I am doing wrong?
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘How to use the_post to change post_title?’ is closed to new replies.