0

I am using ACF(advance custom field) and custom post type plugins to create my own custom post type.

I have successfully created custom post type with custom field. [no problem here]

Then i have display all custom posts to users(front end user) after login. [no problem here].

if front end user(after login) like particular custom post, he/she will fill-up free subscription form against particular custom post and submit it.

Now i want to display all custom posts to users but if user already subscribed for particular post then i want to show it with different color. any solution for this?

1 Answer 1

0

You can add the post ID in the user meta, which is like a space in database to save contents related to an user and a key (the name of the field you're saving). Then, each time you show that post, you can check if the user meta contains the ID of it, and you can change the color.

Once the user subscribes to the post do

add_user_meta( $user_id, 'post_subscribe', $post_id );

And when you show the post

$user_posts = get_user_meta( $user_id, 'post_subscribe' );
if ( in_array( get_the_ID(), $user_posts ) ){
    // Do something
}

PD: To know data about the user logged in (like the ID), you can use wp_get_current_user().

$current_user = wp_get_current_user();
$user_id = $current_user->ID;
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.