Support » Fixing WordPress » echo all custom fields

  • Hi everyone
    does anyone know the PHP code that would do this

    If the value of any custom field from the entire site = the title of the current page then output the name of the custom field as well as the title of the page it is from
    I am trying to build an IMDB basically for my production company

    so I James have a page with the title “James Murphy”

    On the film “Yakim” I was the producer.
    I have made a page called “Yakim” and there is a custom field named Producer, and the value of that custom field is James Murphy

    I want the “james Murphy” page to print out

    Producer – Yakim

    then i want it to search the rest of the site and output the same information from any page that it found my name

    Thanks everyone

Viewing 2 replies - 1 through 2 (of 2 total)
  • I think the following code will do what you want if placed in the Loop for the current page:

    // Select all postmeta with a value matching current Page title
       $post_title = get_the_title();
       $sql = "SELECT m.*, p.*
       FROM $wpdb->postmeta m, $wpdb->posts p
       WHERE m.post_id = p.ID
       AND m.meta_value = '$post_title'
       AND p.post_type = 'page'
       AND p.post_status = 'publish'
       ORDER BY m.meta_key, p.post_title
       $results = $wpdb->get_results($sql);
       foreach ($results as $row) {
          echo "<p>$row->meta_key - $row->post_title </p>";

    If you really meant to select Posts instead of Pages, change the post_type.

    it worked!
    thank you so Much
    Now i just need to make it look pretty
    I really appreciate it!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘echo all custom fields’ is closed to new replies.