Hi,
I would like to display a field group if a user is logged in.
My ultimate goal is :
1 – Create a CPT : Done
2 – Create multiple users : Done
3 – Create a select displayed in each user profile that show all posts from my CPT : Done
4 – Show post content which was assigned to the user : How ?
This is my select :
function add_extra_user_fields( $user ) {
$userid = get_user_meta($user->ID);
$args = array(
'post_type' => 'promotion',
'posts_per_page' => -1,
);
$query = new WP_Query($args);
?>
<table class="form-table">
<tbody>
<tr>
<th>
<label for="">Assigner un programme</label>
</th>
<td>
<select name="testprofile">
<?php if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); ?>
<option value="<?php the_ID(); ?>">
<?php
if (get_user_meta( $userid, userphotos, true) == $userid ){
echo 'selected';
}
?>
<?php the_title(); ?>
</option>
<?php endwhile; endif; ?>
</select>
</td>
</tr>
</tbody>
</table>
<?php
}
add_action( 'show_user_profile', 'add_extra_user_fields' );
add_action( 'edit_user_profile', 'add_extra_user_fields' );
function save_extra_user_fields( $user_id ) {
update_user_meta( $user_id, 'userphotos', sanitize_text_field( $_POST['testprofile'] ) );
}
add_action( 'personal_options_update', 'save_extra_user_fields' );
add_action( 'edit_user_profile_update', 'save_extra_user_fields' );
Hi WDCreativ,
I’m not sure about what you need, you’re talking about displaying a field group to logged in user and about showing post content which was assigned to the user. Can you tell me more ?
What do you want to display : CPT Content ? Field Group ? …
Where : In backend ? Frontend ? On user profile ? On CPT ? …
With wich rules : Display it if you assign user to the CPT ? When user select the CPT ID with the select field ? …
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
π Weβre excited to announce we've released Composer support for installing ACF PRO.
— Advanced Custom Fields (@wp_acf) January 31, 2023
π #ComposerPHP fans rejoice!
β¨ Please see the release post for all the details and full instructions. https://t.co/ebEfp61nlR
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.