• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Ani's Webdev Blog

A learning diary of website development

  • Home
  • Demo
    • Ajax Contact Form
  • WordPress
  • Front-end
  • Backend

WordPress functions returns with var_dump (TO BE CONTINUED)

Modified on: January 4, 2021

Sometimes you may want to know what a function outputs. Here is hopefully a good cheatsheat for you.

Table of contents

  1. get_terms
    1. get_term_link
      1. get_queried_object
        1. term_exists
          1. wp_insert_term
            1. wp_set_object_terms

              get_terms

              Purpose: Get the term for a specific taxonomy (Developer page).

              Output

              • If term found, return an array of WP_Term object
              • If term does not exist, return WP_Error object
              PHP

              Example use: Find top-level terms from a category terms list.

              PHP

              get_term_link

              Purpose: Get the term permalink. (Developer page)

              Output

              • WP_Error object if not found
              • A string of url if term found
              HTML

              Example use: print out the term links for each term found in category.

              HTML

              get_queried_object

              Purpose: To retrieve the current queried object (e.g from the page load) (Developer page).

              Output

              • In a post page, it outputs WP_Post object
              • In an archive page, it outputs WP_Term object
              • In an author page, it outputs WP_User object

              Post page:

              PHP

              Category archive page:

              PHP

              Author page:

              PHP

              Example use

              Return the tag name in uppercase first letter in an archive page:

              PHP

              term_exists

              Purpose: Determines whether a taxonomy term exists, (possibly to check under a parent term) (Developer page).

              Output

              • If success, output an array with ‘term_id‘ and ‘term_taxonomy_id‘.
              • If fail, returns null.
              PHP

              Example use

              PHP

              wp_insert_term

              Purpose: Add a new term to the database, possibly to choose ‘description’, ‘parent’, ‘slug’ or ‘alias_of’ (Developer page).

              Output (example)

              • If successful, output like below
              • If fail, output a WP_Error instance
              PHP

              Example use

              Set a term name under a parent term

              HTML

              wp_set_object_terms

              Purpose: Create Term and Taxonomy Relationships. (Developer page).

              Output

              • If failed, output is a WP_Error.
              • If success, output as an array of term ids
              PHP

              Example use: Set multiple tag terms for one post.

              PHP

              Filed Under: Wordpress, Wordpress Plugins, WordPress Themes Tagged With: php

              Recent posts

              WordPress: Create custom post type programmatically

              [WordPress] Open Images in Posts into Lightboxes On Clicks (Without Plugins)

              Mangools Review: A Productive SEO tool for The Affiliates

              Reader Interactions

              You are here: Home / Wordpress / WordPress functions returns with var_dump (TO BE CONTINUED)

              Leave a Reply Cancel reply

              Your email address will not be published. Required fields are marked *

              Primary Sidebar

              Hello! My name is Anh. I am a front-end developer in Oulu, Finland. Currently, I work with PHP, HTML, CSS, JavaScript and love writing about them. Please feel free to join the discussion!

              FOLLOW MY BLOG

              Thank you for visiting this website! I hope you find something useful here :). Contact me by email: anh@anhkarppinen.com.