• Resolved emazero

    (@emazero)


    hi,
    I need to show a list of posts in page by using custom fields key.
    here is my condition:
    – 1 page (it’s the page of brand XYZ)
    – n posts (just some XYZ products)
    every post has XYZ setted as custom field (brand=XYZ)

    I’m searching something (plugins?) to show all XYZ branded posts in the XYZ page.. it’s a sort of related posts feature but still can’t find something matching with this..

    any help please?
    thanks

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter emazero

    (@emazero)

    ..of course I can’t use categories or tags.. that would be too easy!!

    So something like a a page of posts?

    Thread Starter emazero

    (@emazero)

    thanks man,
    unfortunatelly it doesn’t help me.

    1st I’m working with custom fields..
    2nd I’d need some shortcode to put in my pages.. a shortcoce where I can define the custom field I need.

    Need somethin does this:
    In XYZ page show me all posts with XYZ value custom fields
    In ABC page show me all posts with ABC value custom fields
    ..and so on

    There is an example in that section that shows a loop based on custom fields, so you could create two custom page templates – 1 for each type that you need.

    If you want to tackle this via a shortcode, then you will still need to build a secondary query based on custom fields but, this time, using the Shortcode_API.

    Thread Starter emazero

    (@emazero)

    sorry but..
    loop based on custom fields in the axample uses the custom field value to define a category and than shows all the posts in that category..
    that’s pretty closed to my needs..
    How can I use it to show posts with that custom filed, and not category?
    I mean.. posts are in different categories but have the same custom field value (ex. brand = xyz)

    Thread Starter emazero

    (@emazero)

    <?php
     $querystr = "
        SELECT $wpdb->posts.*
        FROM $wpdb->posts, $wpdb->postmeta
        WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id
        AND $wpdb->postmeta.meta_key = 'tag'
        AND $wpdb->postmeta.meta_value = 'email'
        AND $wpdb->posts.post_status = 'publish'
        AND $wpdb->posts.post_type = 'post'
        AND $wpdb->posts.post_date < NOW()
        ORDER BY $wpdb->posts.post_date DESC
     ";
     $pageposts = $wpdb->get_results($querystr, OBJECT);
    ?>

    [Please post code or markup snippets between backticks or use the code button.]

    this works well.
    the point is that the piece AND $wpdb->postmeta.meta_value = ’email’ declares the value in the loop.
    My page is unique for different values so.. how can I make the postmeta.meta_value a variable?
    Can I use the same meta_value of the page?
    something like:

    $brandvalue = get_post_meta($posts[0]->ID, 'brand', true);

    how can I combine the 2 codes?
    I’m not expert in php.. sorry
    thanks so much

    Thread Starter emazero

    (@emazero)

    here is my solution:
    AND $wpdb->postmeta.meta_value = ‘”.stripslashes($brandvalue).”‘

    thanks

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Posts list by custom fields’ is closed to new replies.