• Resolved DenisCGN

    (@deniscgn)


    Hello,

    I need some help to get the exact 1 CPT “artist” URL from an author ID.

    The goal is to change the author_link to this custom post type “artist” of the author.

    I allready got the author ID and I know how to change the author link by using the author_link filter.

    So, how do I get the custom post type “artist” URL where the author ID is $global ID.

    I know I can do this by customize a query, but, cause there is only ONE cpt for each author I am looking for some shorter way to get this URL or PERMALINK.
    die
    Thanks for help,
    Cheers,
    Denis

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

    (@bcworkz)

    You have not indicated the crucial bit of information needed to do this. How is the CPT related to the author? For example, there could be a custom field that contains the author ID or display name, or something. Or going the other way, a user meta entry containing the CPT ID for the user/author. If there is not any kind of relationship, you need to create one.

    Unless there is a one to one relationship like CPT ID in user meta, you are probably still looking at making a custom query to locate the proper post. Not a big deal, after all, some kind of query will be needed to simply get a single post even if you know the ID. The query may be embedded in a function like get_post(), but there’s still a query somewhere.

    Thread Starter DenisCGN

    (@deniscgn)

    Hello bcworkz,

    the relation is, that during the registration of a new USER, I directly create a new CPT (ARTIST). So there is a relation. The Author of the CPT (artist) is this author.

    The reason is…I dont want to show the author.php page. This should be overwritten by the CPT (artist) page.

    I know that I ca to a query…select CPT(artist) where authorID = $authorID LIMT 1. This will get me exact that post.

    I just hoped it will work with something like get_permalink(‘customPostType’, authorID).

    Because there is only one CPT (artist) for each author.

    Cheers,
    Denis

    Moderator bcworkz

    (@bcworkz)

    Ah, I see now. Thanks for explaining further.
    If your goal is to avoid writing an SQL query, you could use get_posts() or a new WP_Query object to get the post. Of course these end up making a query anyway. Which way you go is mainly a matter of personal preference. get_posts() probably makes your code more readable than the other choices. An SQL query is somewhat more efficient, but no one would notice unless your site has extremely heavy traffic.

    Thread Starter DenisCGN

    (@deniscgn)

    Thanks a lot!

    Denis

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Get exact CPT from the authorID’ is closed to new replies.