• LifterLMS
  • Knowledge Base
  • Academy
  • Blog
  • Podcast
  • Contributors
  • My Account

LifterLMS LifterLMS

  • Code Reference
  • REST API
  • LLMS-CLI

Code Reference

Skip to content
Filter by type:
Search
Browse: Home / Code Reference / Functions / llms_get_user_postmeta()

llms_get_user_postmeta( int $user_id, int $post_id, string $meta_key = null, bool $single = true, string $return = 'meta_value' )

Get user postmeta data or dates by user, post, and key.

Contents

  • Parameters
  • Return
  • Source
  • Related
    • Uses
    • Used By
  • Changelog
  • User Contributed Notes

Parameters #Parameters

$user_id

(int) (Required) WP User ID.

$post_id

(int) (Required) WP Post ID.

$meta_key

(string) (Optional) Meta key, if not supplied returns associative array of all metadata found for the given user / post.

Default value: null

$single

(bool) (Optional) If true, returns only the data.

Default value: true

$return

(string) (Optional) Determine if the meta value or updated date should be returned [meta_value,updated_date].

Default value: 'meta_value'


Top ↑

Return #Return

(mixed)


Top ↑

Source #Source

File: includes/functions/llms.functions.user.postmeta.php

	function llms_get_user_postmeta( $user_id, $post_id, $meta_key = null, $single = true, $return = 'meta_value' ) {

		$single = is_null( $meta_key ) ? false : $single;

		$res = array();

		$metas = _llms_query_user_postmeta( $user_id, $post_id, $meta_key );
		if ( count( $metas ) ) {
			foreach ( $metas as $meta ) {
				if ( $meta_key ) {
					$res[ $meta_key ][] = maybe_unserialize( $meta->$return );
				} else {
					$res[ $meta->meta_key ][] = maybe_unserialize( $meta->$return );
				}
			}
		}

		if ( $single ) {
			return count( $res ) ? $res[ $meta_key ][0] : '';
		} elseif ( $meta_key ) {
			return count( $res ) ? $res[ $meta_key ] : array();
		}

		return $res;

	}

Expand full source code Collapse full source code View on GitHub


Top ↑

Related #Related

Uses #Uses

Uses
Uses Description
includes/functions/llms.functions.user.postmeta.php: _llms_query_user_postmeta()

Query user postmeta data.

Top ↑

Used By #Used By

Used By
Used By Description
includes/class-llms-engagement-handler.php: LLMS_Engagement_Handler::handle_email()

Send an email engagement

includes/models/model.llms.student.php: LLMS_Student::get_enrollment_trigger()

Get the enrollment trigger for a the student’s enrollment in a course


Top ↑

Changelog #Changelog

Changelog
Version Description
3.21.0 Introduced.

Top ↑

User Contributed Notes #User Contributed Notes

You must log in before being able to contribute a note or feedback.

© 2014 - 2023 LifterLMS · Privacy Policy · Terms and Conditions

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.