llms_get_order_by_key( string $key, string $return = 'order' )

Retrieve an LLMS Order ID by the associated order_key.

Parameters Parameters


(string) (Required) The order key.


(string) (Optional) Type of return, "order" for an instance of the LLMS_Order or "id" to return only the order ID.

Default value: 'order'

Top ↑

Return Return

(mixed) null when no order found, LLMS_Order when $return = 'order', or the WP_Post ID as an int.

Top ↑

Source Source

File: includes/functions/llms.functions.order.php

function llms_get_order_by_key( $key, $return = 'order' ) {

	global $wpdb;

	$id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM {$wpdb->prefix}postmeta WHERE meta_key = '_llms_order_key' AND meta_value = %s", $key ) ); // no-cache ok.

	if ( $id && 'order' === $return ) {
		return new LLMS_Order( $id );

	// Return an int not a numeric string.
	return $id ? absint( $id ) : $id;


Top ↑

Changelog Changelog

Version Description
3.30.1 Return a real int (instead of a numeric string).
3.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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