• Resolved mukethedude

    (@mukethedude)


    I have a custom post type called ‘machine’

    a machine belongs to different types (‘machine-type’) (taxonomie)

    a machine is tagged with different tags (‘machine-tag’) (terms)

    when i print_r $taxonomies = get_object_taxonomies( ‘machine’);

    i get:

    Array
    (
    [0] => machine-type
    [1] => machine-tags
    )

    how i get a list of all existing machine-types (i added 4 via backend)

    how i get the machine-type of a single post (single machine)
    how i get the machine-tags of a single post (single machine) (i added several tags via backend)

    Thanks for your help
    br muki

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

    (@bcworkz)

    To get all terms within a given taxonomy, use get_terms().
    print_r( get_terms(['taxonomy' => 'machine',]));

    It seems you’re conflating terms and taxonomies. A taxonomy is used to organize things. “category” and “post-tag” are built-in taxonomies. The category terms or post tags you create under those taxonomies are all terms. Post types are related to overall taxonomies. Individual posts are assigned terms within a taxonomy.

    Thread Starter mukethedude

    (@mukethedude)

    thanks for the moment, i am sure i get back later ??

    br muki

    Thread Starter mukethedude

    (@mukethedude)

    ok, now iam able to print_r all terms by:
    $taxonomies = get_terms( ‘machine-tags’); and
    $taxonomies = get_terms( ‘machine-type’);

    but how to get all machines with a special term.

    my example: i have machines and accessories: accessories belong to certain machines.
    in my CPT accessory i have tags (accessory-tags) called as one or more of the machines. How to get the link ?

    sorry for my english.

    br muki

    Moderator bcworkz

    (@bcworkz)

    If you want to get all post type machine posts which are assigned a particular taxonomy term, use get_posts(). In the passed args, specify the post type you want and use the “tax_query” arg to specify which term(s) should be assigned to the posts to be returned. You can use any of the args available for a WP_Query object. There are several examples for making proper use of the “tax_query” arg on the linked page.

    How are accessory posts related to machine posts? Do they have a taxonomy in common? If so, for a given accessory, get its assigned term and use that in “tax_query” to get machine posts. For any given post you can get its permalink with get_permalink(). If not called within a standard WP loop, you’ll need to pass the post’s ID.

    No need to apologize for your English skills, I understand you, that’s all that matters ?? I hope you understand me, I have difficulty writing simply.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘get all types and terms’ is closed to new replies.