Title: Invalid title when using user defined fields
Last modified: August 4, 2017

---

# Invalid title when using user defined fields

 *  Resolved [hgassner](https://wordpress.org/support/users/hgassner/)
 * (@hgassner)
 * [8 years, 10 months ago](https://wordpress.org/support/topic/invalid-title-when-using-user-defined-fields/)
 * Hello!
 * First thanx for this great PlugIn!
 * I’m using user defined fields to change the post title for specific posts, e.
   g. adding “guest post” to the title, if the user defined variable ‘Gastbeitrag’
   is set. See the code below.
 * // add text for guest post to title
    add_filter( ‘the_title’, ‘ai_guest_post’);
   function ai_guest_post( $title ) { global $post;
 *  $guest_post = get_post_meta($post->ID, ‘Gastbeitrag’, true);
    if ($guest_post
   == ‘true’ && in_the_loop() ) { $guest_text = “<br><span style=’font-size: 50%;
   font-style: italic’>Gastbeitrag</span>”; return $title.$guest_text; }
 *  return $title;
    }
 * But now when displaying a guest post I see the added “guest post” (‘Gastbeitrag’
   in the code above) text for ALL posts in the TOP 10 list and not only for guest
   posts.
 * So it seems that TOP 10 uses the postId of the displayed post for all posts in
   the TOP 10 list when setting the title.
 * Any help would be appreciated!
 * Thank you very much
    Horst

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Plugin Author [Ajay](https://wordpress.org/support/users/ajay/)
 * (@ajay)
 * [8 years, 10 months ago](https://wordpress.org/support/topic/invalid-title-when-using-user-defined-fields/#post-9383562)
 * Can you try using the function to filter `tptn_post_title`
 *  Thread Starter [hgassner](https://wordpress.org/support/users/hgassner/)
 * (@hgassner)
 * [8 years, 10 months ago](https://wordpress.org/support/topic/invalid-title-when-using-user-defined-fields/#post-9384776)
 * Thank you very much for your answer!
    Unfortunately this does not work but the
   output has changed.
 * The header of the post does not show “Gastbeitrag” anymore and the format of 
   the top list changed a bit.
 * Since it is not possible to uploaf pictures here directly I’ve uploaded them 
   in a public area. Please take a look – it might help you finding another answer.
 * [the_title](http://austria-insiderinfo.com/public/the_title.PNG)
    [tptn_post_title](http://austria-insiderinfo.com/public/tptn_post_title.PNG)
 * Have fun
    Horst
 *  Plugin Author [Ajay](https://wordpress.org/support/users/ajay/)
 * (@ajay)
 * [8 years, 10 months ago](https://wordpress.org/support/topic/invalid-title-when-using-user-defined-fields/#post-9384870)
 *     ```
       add_filter( ‘ tptn_post_title’, ‘tptn_ai_guest_post’, 10, 2 );
       function tptn_ai_guest_post( $title, $result )
       {
       $guest_post = get_post_meta($result->ID, ‘Gastbeitrag’, true);
       if ($guest_post == ‘true’ && in_the_loop() )
       {
       $guest_text = “<br><span style=’font-size: 50%; font-style: italic’>Gastbeitrag</span>”;
       return $title.$guest_text;
       }
   
       return $title;
       }
       ```
   
 * I’ve changed the code around, but can you let me know if this works.
 * Another option if you don’t want to display Gastbeitrag, you could filter the
   tptn_post_title to have a filter priority 99 and strip out the $guest_text you
   have above that was added
 *  Thread Starter [hgassner](https://wordpress.org/support/users/hgassner/)
 * (@hgassner)
 * [8 years, 10 months ago](https://wordpress.org/support/topic/invalid-title-when-using-user-defined-fields/#post-9385255)
 * Thank you Ajay! Played around with your suggested solution and it principally
   worked.
 * But I then had no more “Gastbeitrag” text in the header of my singles post and
   archives. But your suggestion helped a lot!
 * Here is my complete and working solution (‘Gastbeitrag’) in post title and only
   in these posts in the top list which are indeed guest posts.
 *     ```
       // =================================================================================
       // guest posts
       // =================================================================================
   
       // add text for guest post to title (non top list areas like post header and archives)
       add_filter( 'the_title', 'ai_guest_post' );
       function ai_guest_post( $title )
       {  
          global $post;
          $guest_text = "Gastbeitrag";
   
          $guest_post = get_post_meta($post->ID, 'ai_guest_post', true); 
          if ($guest_post == 'true' && in_the_loop() )
          {
       	  return $title."<br><span style='font-size: 50%; font-style: italic'>".$guest_text."</span>";
          }  
   
          return $title;
       }
   
       // handle text for top list
       add_filter( 'tptn_post_title', 'tptn_ai_guest_post', 99, 2 );
       function tptn_ai_guest_post( $title, $result )
       {  
          // first always remove text added by 'the_title' filter
          $guest_text = "Gastbeitrag";
          $title = str_replace($guest_text, '', $title);
   
          $guest_post = get_post_meta($result->ID, 'ai_guest_post', true);
          if ( $guest_post== 'true' && in_the_loop())
          {
             // now add text for top list
       	  return $title."<br><span style='font-size: 75%; font-style: italic'>".$guest_text."</span>";
          }  
   
          return $title;
       }
       ```
   
    -  This reply was modified 8 years, 10 months ago by [hgassner](https://wordpress.org/support/users/hgassner/).
 *  Plugin Author [Ajay](https://wordpress.org/support/users/ajay/)
 * (@ajay)
 * [8 years, 10 months ago](https://wordpress.org/support/topic/invalid-title-when-using-user-defined-fields/#post-9385927)
 * Glad to know this work. I’ll do a bit of testing at my end as well to see how
   I can selectively add this. The plugin uses get_the_title which I suspect why
   this is triggering. Bit surprised that in_the_loop is validating true for my 
   posts list as well… that’s for another day!

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Invalid title when using user defined fields’ is closed to new replies.

 * ![](https://ps.w.org/top-10/assets/icon-256x256.png?rev=2986432)
 * [WebberZone Top 10 — Popular Posts](https://wordpress.org/plugins/top-10/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/top-10/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/top-10/)
 * [Active Topics](https://wordpress.org/support/plugin/top-10/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/top-10/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/top-10/reviews/)

 * 5 replies
 * 2 participants
 * Last reply from: [Ajay](https://wordpress.org/support/users/ajay/)
 * Last activity: [8 years, 10 months ago](https://wordpress.org/support/topic/invalid-title-when-using-user-defined-fields/#post-9385927)
 * Status: resolved