• Hi all,

    I am a newbie to WordPress and now my site is built I am trying to do some more sophistiated things.

    I would like to be able to create a new custom post type to capture information about qualifications of individual logged in users. I have figured out how to make a custom post type using PODS and also how to display the data using Elementor Pro. However as the next step I would like to only show the data relating to each individual user so they only ever see their own record. I can’t figure out how to do this. I would also like to be able to allow newly registered users to create / update their own record.

    Ideally the use case would be that a user would create an account and then once logged in could navigate to a page, click a button to create their qualification record (just a single record per user) enter the data and save it. Be able to come back to the record later update and save it. Only be able to see their wn record.

    Can anyone help with a tutorial, plugin or just an overview of how I would go about this please?

    Thanks

    D

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    You need some way to relate a post to a specific user that code can use to relate the two by matching up data fields in the DB. The usual way would be to store the user ID in post meta, but anything that matches exactly will work.

    Then you can alter any attempts to query for this CPT through the “pre_get_posts” action. The callback code would check if the query is for the CPT in question. If so, get the ID or other matching user data and use it to add a query var limiting posts found to those with the proper matching data.

    You also need a way to add or edit the matching user data saved with the post. A custom field will suffice, but there needs to be a way to allow admins to alter the field but not regular users. You can use the “update_post_metadata” filter to enforce this.

    In case you didn’t already know, don’t modify any core code or even your theme code. Create a child theme or create your own custom plugin to contain any custom code you need. Either option is much easier than it sounds.

    Thread Starter dunnydf

    (@dunnydf)

    Is there any tutorial or example you could point me at?

    At the moment I have not done any coding in WordPress so not sure how I would implement your suggestions.

    Thanks

    D

    Moderator bcworkz

    (@bcworkz)

    Sorry, none that I know of. I imagine you are as capable in searching as I am ?? I suggest searching for examples that do elements of what you want as well as for something that does it all. Better chance of success. I can point you to some good reference material. Start here: https://developer.www.ads-software.com/

    Look in the Themes Handbook for info about child themes. The Plugin Handbook has info on starting your own plugin, as well as the use of filters and action hooks. Look up the specific action and filter I mentioned earlier in the Code Reference. The initial hook reference page isn’t entirely useful. You will want to see how core code implements the hook. For that, look in the Related/Used By section of the reference page and follow the link to one of the functions implementing the hook. On the function reference page, there will be a source code listing where you can see how the hook is used.

    Specifically about the pre_get_posts action, the old Codex reference (which is in the process of being replaced) has some good information not yet transferred to the new docs.

    Thread Starter dunnydf

    (@dunnydf)

    Thank you so much for the additional information.

    Regards

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Limiting custom post type records by author’ is closed to new replies.