Ralationship between custom post type and users
Author | Posts |
---|---|
April 22, 2013 at 2:10 pm 2704 | |
noomia | Hi ! First of all, thank you for your great plugin ! I work with it for 1week and it's incredible what it allows me to do ! Thanks ! First of all, I have a custom post types wich is companies. It is a listing of the web agencies in my country. What I need is to “link” users to companies. So I was wondering if we can create a select box with all the items of a custom post type on the profile page. Like the plugin “Advanced Custom Fields” does with his “RelationShip” field. How could I do that right now ? I don't want to store the company name, but the company ID, it's more safe :) ! I think it could be great to add this "Relationship" feature in a future update, it's very useful :) ! Thank you very much, Noomia |
April 22, 2013 at 8:19 pm 2733 | |
Tareq Hasan | Thanks for tip, I am adding this to the todo list. But no ETA, you can implement this currently with the action hook field 🙂 |
April 23, 2013 at 12:01 pm 2770 | |
noomia | Hi Tareq,
Unfortunately, I don’t understand how to deal with the action hook field to achieve my goal… |
April 23, 2013 at 8:57 pm 2796 | |
Tareq Hasan | With the action hook field, you can render your own input area or select area. Lets say you’ve a action hook named `my_own_hook`, you can generate your own fields like this: [php] add_action( ‘my_own_hook’, ‘render_my_own_dropdown’, 10, 3 ); Now as you’ve generated the dropdown on your own, when hit the submit button, save them: [php] add_action( ‘wpuf_add_post_after_insert’, ‘save_my_own_dropdown’ ); |
April 24, 2013 at 9:09 am 2807 | |
noomia | Hi Tareq, Here is what I’ve done : `
|
April 24, 2013 at 9:45 am 2809 | |
Tareq Hasan | The code should be working, the only problem I see in the code is query_posts() function, you should never use that instead of special cases. Use WP_Query and try again. |
April 24, 2013 at 9:51 am 2810 | |
noomia | I’ve forgot to mention that it’s not a post meta, but a user meta. And what if the meta doesn’t exit ? It has to be created… I’ll try wuth WP_Query, but I don’t think that is the problem cause I have all my companies in the dropdown… |
April 24, 2013 at 9:59 am 2812 | |
Tareq Hasan | If it’s user meta, then use update_user_meta(), it’ll be created if it doesn’t exists. |
April 24, 2013 at 11:21 am 2822 | |
noomia | I’ve done what you say, I can’t do it… ` $args= array( $my_companies_query = new WP_Query($args); ?>
|
April 24, 2013 at 11:24 am 2826 | |
Tareq Hasan | Why are you updating the user meta with the post ID? Shouldn’t it be the user id? |
April 24, 2013 at 11:32 am 2827 | |
noomia | I have changed the and But nothing changes… Here is the full code : $my_companies_query = new WP_Query($args); ?>
|
April 24, 2013 at 11:34 am 2828 | |
noomia | I feel that it doesn’t go through the wpuf_add_post_after_insert… I mention abose that it’s when I edit user profile… Do I have to change something ? |
April 24, 2013 at 12:32 pm 2833 | |
noomia | After further investigation, I’ve found `wpuf_update_profile_resp` So I use it like that, instead of |
April 24, 2013 at 8:41 pm 2840 | |
Tareq Hasan | No, you shouldn’t modify the response. I tested your code from above post, it perfectly saved the post id to that user profile. |
April 24, 2013 at 9:02 pm 2843 | |
noomia | it’s weird :/ ! With update_profile_resp, it works… But with the other code it doesn’t :/ ! Could you maybe have look on my dev website ? |
April 24, 2013 at 9:08 pm 2844 | |
Tareq Hasan | I thought you were adding the field in post form? Are you adding this on edit profile? Then the `wpuf_add_post_after_insert` won’t work. You need to use `wpuf_update_profile` hook. |