Title: Saving Post Title Permalink To Variable
Last modified: August 19, 2016

---

# Saving Post Title Permalink To Variable

 *  Resolved [dokueki](https://wordpress.org/support/users/dokueki/)
 * (@dokueki)
 * [16 years, 7 months ago](https://wordpress.org/support/topic/saving-post-titlepermalink-to-variable/)
 * Hey. I’m making a plugin for my WordPress, and I need the the_content() to also
   have information about the posts’s title and permalink. To do that, I attempted
   to add a filter/action (tried both) to the_ID and letting them save the info 
   to a variable. Here’s the code I used for those particular parts:
    `add_filter('
   the_ID', 'wooshare_get_title'); // I also tried add_action instead add_filter('
   the_content', 'show_wooshare_links');
 * $wooshare_post_info = Array();
 * function show_wooshare_links($content)
    { global $wpdb, $wooshare_post_info; 
   $table_name = $wpdb->prefix . 'wooshare_links'; $query = "SELECT `name`,`url`,`
   image`,`text`,`title` FROM `$table_name`“; $buttons = $wpdb->get_results($query,
   OBJECT); $insert = ”; foreach ($buttons as $button) { $find = Array( ‘”‘, ‘%title%’,‘%
   url%’ ); $replace = Array( ‘%22’, $wooshare_post_info[‘title’], $wooshare_post_info[‘
   permalink’] ); $button->url = str_replace($find, $replace ,$button->url); $insert.
   = ‘url . ‘” class=”wooshare_link” id=”wooshare_’ . $button->name . ‘” title=”‘.
   $item->title . ‘”><img src=”‘ . $button->image . ‘” alt=”” class=”wooshare_icon”
   id=”wooshare_’ . $button->name . ‘_icon” /> ‘ . $button->text . ‘‘; } return 
   print_r($wooshare_post_info) . $content . $insert; }
 * function wooshare_get_title($id)
    { global $wpdb, $wooshare_post_info; $table_name
   = $wpdb->prefix . ‘posts’; $post = $wpdb->fetch_row(“SELECT `post_title`,`guid`
   FROM `$table_name` WHERE `id` = ‘$id'”, OBJECT); echo $post->post_title; $wooshare_post_info
   = Array(‘title’ => $post->post_title, ‘permalink’ => $post->guid); return print_r(
   $wooshare_post_info) . $id; }
 * But the variable stays empty. I can’t echo anything during the_ID so I can’t 
   figure out if it ever gets the data from there or not.

The topic ‘Saving Post Title Permalink To Variable’ is closed to new replies.

## Tags

 * [add_action](https://wordpress.org/support/topic-tag/add_action/)
 * [add_filter](https://wordpress.org/support/topic-tag/add_filter/)
 * [global](https://wordpress.org/support/topic-tag/global/)
 * [the_content](https://wordpress.org/support/topic-tag/the_content/)
 * [variable](https://wordpress.org/support/topic-tag/variable/)

 * 0 replies
 * 1 participant
 * Last reply from: [dokueki](https://wordpress.org/support/users/dokueki/)
 * Last activity: [16 years, 7 months ago](https://wordpress.org/support/topic/saving-post-titlepermalink-to-variable/)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
