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

LifterLMS LifterLMS

Code Reference

  • Home
  • 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

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

Description #Description


Parameters #Parameters

$user_id

(int) (Required) WP User ID

$post_id

(int) (Required) WP Post ID

$meta_key

(string) (Optional) 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 ↑

Changelog #Changelog

Changelog
Version Description
3.21.0 Introduced.

Top ↑

Related #Related

Top ↑

Uses #Uses

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

Query user postmeta data This function is marked for internal use only.

Top ↑

Used By #Used By

Used By
Used By Description
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 ↑

User Contributed Notes #User Contributed Notes

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





Permalink:
© 2014 - 2019 LifterLMS · Privacy Policy · Terms and Conditions