I am using a WordPress Form Plugin to store data. There’s this text field which I’m using to store links such as http://example.com. I want to make the links clickable and where possible change it with HTML link markup
When I make a query inside the database like so, I see all the links listed which I want to alter
SELECT * FROM `wp_frm_item_metas` WHERE `meta_value` LIKE '%http://localhost/group1/add-temp/?frm_action=edit&entry=%' ORDER BY `wp_frm_item_metas`.`created_at` DESC
The links are already displaying in the frontend. Here is what the frontend links look like.
I’m learning to do this in localhost, WordPress
Advertisement
Answer
You could build a function around it like the following
public function wrap_links() { global $wpdb; $sql = "SELECT * FROM {$wpdb->prefix}frm_item_metas WHERE meta_value LIKE '%http://localhost/group1/add-temp/?frm_action=edit&entry=%'"; $results = $wpdb->get_results( $sql, 'ARRAY_A' ); foreach ($results as $result) { echo '<a href="' . $result['name_of_link_column'] . '" target="_blank">' . $result['name_of_link_column'] . '</a>'; } }
Function with current user id query
public function wrap_links() { global $wpdb; $userid = get_current_user_id(); $sql = $wpdb->prepare("SELECT * FROM {$wpdb->prefix}frm_item_metas WHERE meta_value LIKE '%http://localhost/group1/add-temp/?frm_action=edit&entry=%' AND user_id = %d", $userid); $results = $wpdb->get_results( $sql, 'ARRAY_A' ); foreach ($results as $result) { echo '<a href="' . $result['name_of_link_column'] . '" target="_blank">' . $result['name_of_link_column'] . '</a>'; } }