WordPress.org

Ready to get started?Download WordPress

Forums

Group common values of custom field (3 posts)

  1. Micbow
    Member
    Posted 1 year ago #

    Hi

    I'm after some help with just one line of this code please. (line 10 ?)

    Basically what it does is list links (with titles) to all posts created by the "author" of the post in question.

    What I'd like to do is change it from the post author to a Custom Field I've created called "business" and group all posts that have the same/common value for the custom field "business"

    I'm pretty sure it's just line 10 that needs to be changed

    [Code moderated as per the Forum Rules. The maximum number of lines of code that you can post in these forums is ten lines. Please use the pastebin]

    Thanks in advance, much appreciated as I've searched everywhere for this.

  2. Micbow
    Member
    Posted 1 year ago #

    Hi

    I'm after some help please with just one line of this code. (line 1 ? goes in single.php)

    Basically what it does is list links (with titles) into a table for all the posts created by the "author" of the post in question.

    What I'd like to do is change it from the post author to a Custom Field I've created called "business" and group all posts that have the same/common value (for the custom field "business") as the post page on which they are displayed.

    I'm pretty sure it's just line 1 that needs to be changed

    1 <?php $i=1; $posts = query_posts('caller_get_posts=1&author='.$post->post_author.'&post_type=post&post_status=publish&orderby=post_date&order=DESC'); foreach($posts as $post) { ?>
    2 <tr <?php if($i%2){ ?>class="odd"<?php } ?>>
    3 <td>" rel="nofollow" ><?php echo $post->post_title; ?></td>
    4 <td><?php echo get_the_date(); ?></td>
    5 </tr>
    6 <?php $i++; }} ?>
    7 </tbody>

    Thanks in advance

  3. bcworkz
    Member
    Posted 1 year ago #

    Custom fields are stored in the postmeta table, separate from the posts table that query_posts() accesses. You need a SQL query that joins the two tables. I'm not sure this is even possible with query_posts. You may need to resort to a more generic query method to get what you want, such as $wpdb->get_results().

    I'm not sure what you mean by grouping posts as a post page, but it's probably just a matter of crafting the proper SQL query, perhaps by specifying a certain set of GROUP BY columns.

Topic Closed

This topic has been closed to new replies.

About this Topic