hello guys, i'm pretty new to php and to this forum, but i need a little bit of help and i hope i can find it here :).

I need a wordpress page to create dynamic links, using the url and the wordpress database (or a new database¿?) to grab information.

So i need create a database with 3 columns, the link ID #, and two separate links, then i guess i need to specify somehow in the url what id and which link to use so i can populate the wordpress page.

I would like to know how to format the url and how to format the links too, i'm lost :(.

For example, if the link is: mywebsite.com?id=1, then it will pull the links the database associated with id=1

thanks in advance!
Adrian

Dani AI

Generated

Short primer that follows up on and the pointers from and : two practical ways to drive dynamic links in WordPress are (A) use native posts (or a custom post type) with postmeta, or (B) keep a custom table and query it via $wpdb. Choice depends on scale and admin needs: postmeta is easiest for small sets and works with the WP admin; a custom table is better for large volumes or complex indexing.

Using postmeta (simpler)

  • Store each link pair as a post (or CPT) and use get_post_meta to fetch stored URLs.
  • Sanitize the incoming identifier (absint() for numeric IDs), and escape output with esc_url() before printing.
  • Example retrieval pattern:
$id = isset($_GET['link_id']) ? absint($_GET['link_id']) : 0;
if ($id) {
    $url_a = get_post_meta($id, 'url_a', true);
    $url_b = get_post_meta($id, 'url_b', true);
    if ($url_a) echo '<a href="' . esc_url($url_a) . '">Link A</a>';
    if ($url_b) echo '<a href="' . esc_url($url_b) . '">Link B</a>';
}

Using a custom table (for performance)

  • Example minimal schema:
CREATE TABLE wp_dynamic_links (
  id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  slug VARCHAR(100) NOT NULL,
  url_a TEXT NOT NULL,
  url_b TEXT NOT NULL
) DEFAULT CHARSET=utf8;
  • Query safely with $wpdb->prepare and $wpdb->get_row:
global $wpdb;
$row = $wpdb->get_row(
  $wpdb->prepare("SELECT url_a, url_b FROM {$wpdb->prefix}dynamic_links WHERE id = %d", $id),
  ARRAY_A
);
  • For prettier URLs, add rewrite tags/rules and call flush_rewrite_rules() on activation.

Security and troubleshooting

  • Always prepare SQL and sanitize/escape input/output ($wpdb->prepare, absint, sanitize_text_field, esc_url). See the $wpdb prepare docs and esc_url docs for details.
  • If links do not appear: enable WP_DEBUG, verify table names use $wpdb->prefix, check that the correct template/page is loaded, and flush rewrite rules after registering any new rules.

Recommended Answers

All 2 Replies

Hello Adrian.
Do you still need help on this?

Regards,
Daniel

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.