Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End How do I get custom fields matching the current post title?

  • This topic is empty.
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #32147

    Hi everyone.
    I´m obviously a newbie both here and when it comes to PHP and wordpress. I got a site up and running with wordpress much thanks to the excellent tutorials provided by Chris. My problem is the following:
    I have posts about authors (cat=7) and I would like to use the post title which is the author name as a condition to find posts in another category (cat=5) with a custom field named ‘Author’. From all posts that match I would then like to get some other custom fields (‘ISBN’, ‘Binding’ ‘Pris’, ‘Lagerstatus’ and ‘post-image’) so I can display that information in the sidebar. I´m thinking of putting it in some sort of slider.
    I have not been able to find any information on how to set up such a condition, so any help or pointers in the right direction would be greatly appreciated.

    I´m including an image describing what I´m trying to do.
    To the image describing the problem.

    #53491
    DogsGhost
    Member

    Check out Chris’s screencast #65, gives a good overview on custom fields. You should be able to adapt what he goes over there.

    #53493

    Hi.
    I did actually watch that video really carefully in the hope of finding a way to do what I am trying to do. But, the way Chris does it with his recommended products would in my case result in a single.php that is about a mile long and it would require a lot of additional custom fields.
    The thing is that I simply want single.php to recognize what the current title of the page is and match that against a custom field ‘Author’ which is not in this post but a different category of posts, so that I can pull out some custom field data from those posts. I would really rather not add a bunch of custom fields to the posts for this.
    The title of the current page is an exact match to the content of the custom field ‘Author’ on all the relevant post so there is no chance that I would get anything that I don´t need.
    I am currently looking at a way of doing this with tags which seem to work, but it would be much more elegant if it could be done using the current page title, since that would mean that I would not need to add any additional data.

    I have a feeling that this would be rather simple if I only knew enough php, but like I mentioned in my first post I am a total newbie when it comes to php. My description of the problem might even be more complicated than the solution.

    #51178
    magnuseide
    Member

    Hi
    I’ve been in almost the exact same situation when making a website for a publishing house, crosslinking book and author posts.

    You might be able to use this :


    $args = array(
    'numberposts'=> -1,
    'post_type'=> 'post',
    'cat' => 5,
    'meta_key'=>'author',
    'meta_value'=>get_the_title()
    );
    $books = get_posts($args);
    echo '';
    ?>

    Tweak it with get_post_meta($book->ID, ‘metakey’, true) to recieve other meta data per post(book) you recive.

    #50470

    Thank you magnuseide. That was exactly what I was looking for. It is working perfectly without any additional data.

    #81874
    jaffa
    Member

    Hi Guys

    I am trying to do something similar but as the original poster I am new to both php and wordpress.

    I have a number of pages about each team member, I would like to be able to match the title of the page (which is the team members name) to a custom field used in the posts.

    I would then like to be able to display the latest 5 posts written by that team member.

    Any idea’s?

    Thanks

    #82618
    jaffa
    Member

    After modifying the code above I got it to work!

    I am trying to add thumbnail images to the list though not having much luck. Is it possible?

Viewing 7 posts - 1 through 7 (of 7 total)
  • The forum ‘Back End’ is closed to new topics and replies.