WordPress.org

Support

Support » WP-Advanced » [Resolved] Link post together with custom metadata

[Resolved] Link post together with custom metadata

Viewing 3 replies - 1 through 3 (of 3 total)
  • Sorry for bumping but no one has a clue?

    I’d add some hidden posts (category = metadata, hide all metadata posts on displayed pages).

    To display the info, you’ll SELECT the metadata WHERE post_title = distillery name AND category = metadata.

    It’s a hack, but then again so is anything else.

    You could alternatively create pages with that info, and they’ll just be private (hidden) pages. You can select by name and pull whatever info you want. Just be sure that you exclude these pages from any page listings.

    OR, if you’re the only one posting (or you don’t display user info anyhow), make a “user” called the distillery name, and enter the distillery info into the user boxes. (This can be confusing unless you’re willing to hack the core.) I.e. “nicename” = displayed distillery name. “url” = website of distillery (if available) etc.

    Thanks for the reply!

    I figured it out in another way. I used the wpdb class to query the db. This worked fine for me. Here’s the code that I used.

    $key="Distillery";
    $distilleryvalue = get_post_meta($post->ID, $key, true);
    $distilleryvalue = $distilleryvalue . " Distillery";
    $distillery_id = $wpdb->get_row("SELECT * FROM $wpdb->posts WHERE post_title LIKE '%$distilleryvalue%'");
    $distillery_id = $distillery_id->ID;
    $distillery_meta = $wpdb->get_col("SELECT meta_value FROM $wpdb->postmeta WHERE post_id = $distillery_id");
    
    echo '<h2>Distillery</h2>';
    echo '<ul>';
    echo '<li>Region: ' . $distillery_meta[3] . '</li>';
    echo '<li>Country: ' . $distillery_meta[7] . '</li>';
    echo '<li><a href="' . $distillery_meta[9] . '">Official website</a>';
    echo '<li><a href="' . $distillery_meta[0] . '">Location (at Google maps)</a>';
    echo '<li><a href="' . $distillery_meta[1] . '">Buy bootles from this distillery (at the Whisky Exchange)</a>';
    echo '<li><a href="' . $distillery_meta[2] . '">Read more at Wikipedia</a>';
    echo '<ul>';
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Resolved] Link post together with custom metadata’ is closed to new replies.