Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wordpress User Custom Field (Checkboxes) retrieve and update - from anywhere

I've created a custom field (Checkboxes) in Wordpress > Users > Profile Fields. My site is an omni site for news, so it collects news from 20 different sources via RSS, and adds them ass posts in my Wordpress site. This is how my custom field looks like:

enter image description here

If you're only a visitor on my front page I'll show all posts on the startpage.

If you are a logged in user; then you should be able to select and save wich of the 20 sources you want to read in your startpage on my site. This is possible to select and save today, but only from BP User Settings page:

Select and Save sources from BP User Settings

Now, the issue with the Users Profile Settings page is:

a) I do not want to have the form in the tab "Profile > Edit". I want my form on my startpage (above the news flow, for logged on users of course) and perhaps in a widget sometime - anyhow - the most important this is freedom to place (and style) the form wherever I want.

b) The form includes fields I want to remove (Name and Description, i.e. "sources" = field name) etc.

The user on the image above has selected and saved to read news from 2 different sources on my website. The code that handles this is on the startpage in my index.php is:

$sources = xprofile_get_field_data( 'sources', $current_user_id, $multi_format = 'array' );
query_posts(array('category__and'=>array($sources)));

Question Is there a way of retrieving this form and update in from anywhere for logged in users? I don't want to be bound to the idea of only having the form in the Profile Settings page. I want the user to have to form above my news flow on the startpage of my site, so the users gets the feeling of "Oh, I can customize my news flow if I create an account!" - and this should be done from anywhere for logged in users.

like image 590
Fernando Redondo Avatar asked Aug 05 '15 05:08

Fernando Redondo


1 Answers

If I am getting it correctly, you want to display the form to logged in users. Have you tried

<?php if ( is_user_logged_in() ) { ... } ?>  function?

you may also wish to update user fields with

update_user_meta()

like image 70
saq Avatar answered Sep 30 '22 16:09

saq