Wednesday, 15 June 2011

php - Wordpress - Retrieving specific posts from the current user -



php - Wordpress - Retrieving specific posts from the current user -

i have custom post 2 fields, first field beingness user, , sec 1 beingness table, , whenever user logged in, must display of posts have user in 1st field, found:

in wp_user id of user i'll using test have: user_id = 3

in wp_postmeta, have row these values:

-post_id=92 -meta_value=3

and in wp_posts, in id = 92, have specific post name looking for.

i'm pretty confused on how create code dynamically, user able see own posts. and btw, post_author admin, can't utilize field

basiclly, must retrieve post_id wp_postmeta using the meta_value i've seen couple of guides can't understand how it. know must utilize wp_get_current_user(). please explain me detail how accomplish this.

thanks

in functions.php need place hook , hook fired whenever post added or updated need utilize saving post id in post meta table.

function enter_post_id( $post_id ) { wp_get_current_user() // current user id update_post_meta()($post_id, $meta_key, $meta_value, $unique) // add together meta key 'user_id' , place value of user_id meta value } add_action( 'save_post', 'enter_post_id' );

now have match completed , need query through post meta table , post id user , , wp_posts show post's matched id.

hope helps . sense free inquire if have confusion.

php wordpress user

No comments:

Post a Comment