Support » Plugins » Define query_posts from Custom fields!!!

  • Resolved Rodeo Imagination

    (@shiroujune)


    Hi! I’ve been struggling with this for a while now… wonder if this can be done…

    This is my query_posts based on the post-slug.

    <?php query_posts('name=my-post-title-name'); ?>

    What I would like is… to define the “my-post-title-name” from the custom fields when writing a new post. Thought it could use a variable or something… not sure…

    I call a custom field like this…

    <?php if ( get_post_meta($post->ID, 'mykey', true) ) { ?>
             <?php _e("My value: "); echo get_post_meta($post->ID, "mykey", $single=true); } ?>

    Any ideas pretty please?…
    Thanks…

Viewing 8 replies - 1 through 8 (of 8 total)
  • Are you asking how to return a query of your posts, where the custom field value is equal to a value?

    If so it would be something like:

    query_posts('meta_key=mykey&meta_value=my-post-title-name');

    Thread Starter Rodeo Imagination

    (@shiroujune)

    No… I meant… the function is

    query_posts('name=post-slug');

    so name= should remain there, while post-slug should be defined by my custom field key that is equal to a value…

    I am clueless on php… so forgive the raw example…

    but it should be something like:

    query_posts('name=$mypostslug');

    where

    $mypostslug =
    
    <?php if ( get_post_meta($post->ID, 'mykeyslug', true) ) { ?>
    <?php _e("My value: "); echo get_post_meta($post->ID, "mykeyslug", $single=true); } ?>

    something like that… though I know the $ cannot be readable because of the single quotes…

    Might review the available arguments for query_posts. See Template_Tags/query_posts

    Thread Starter Rodeo Imagination

    (@shiroujune)

    Already did… it was from there that I picked:

    Post & Page Parameters

    Retrieve a single post or page.

    * ‘p’ => 27 – use the post ID to show that post
    * ‘name’ => ‘about-my-life’ – query for a particular post that has this Post Slug

    here: http://codex.wordpress.org/Template_Tags/query_posts#Post_.26_Page_Parameters

    It works… I just need to find how to retrieve that value from a custom field…

    Thread Starter Rodeo Imagination

    (@shiroujune)

    Did too. I believe it’s a programming issue… I saw somewhere a code to store information in a variable that could be used later but can’t find it…

    Thread Starter Rodeo Imagination

    (@shiroujune)

    Found my way through it. It was easier than thought…

    <?php $mydiscslug = get_post_meta($post->ID, "disc", $single=true); ?>
    
    <?php query_posts('name=' . $mydiscslug); ?>

    These two lines made the trick. Some conditionals… and it works like a charm: http://www.siamshade-everlasting.com/en/lyrics/binecks_lyrics/2009/kimi-ga-tooku-te/

    Used to retrieve all the content in the “Song Info” stored in another post.

    Hope it helps someone outhere!!!

    Regards!

    Hey could this be edited to work for the following. I dont know PHP that well so here is what i have.

    I want to move the content from bosts which have a custom field of embed and put the data within description. I was going to do this in SQL but is there is a more simple way, this would be great.

    So what i want to do. Post with meta_value = ’embed’ i want to move this the the description field within my post.

    Any help would be great thanks.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Define query_posts from Custom fields!!!’ is closed to new replies.