ap_get_qameta( integer $post_id )

Description #

Get a qameta by post_id

Parameters #

  • $post_id
    integer (Required) Post ID.

Changelog #

VersionDescription
3.1.0Introduced.

Source #

File: includes/qameta.php

function ap_get_qameta( $post_id ) {
	global $wpdb;

	$qameta = $wpdb->get_row( $wpdb->prepare( "SELECT qm.*, p.post_type as ptype FROM {$wpdb->posts} p LEFT JOIN {$wpdb->ap_qameta} qm ON qm.post_id = p.ID WHERE p.ID = %d", $post_id ), ARRAY_A ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery

	// If null then append is_new.
	if ( empty( $qameta['post_id'] ) ) {
		$qameta = array( 'is_new' => true );
	}

	$qameta = wp_parse_args( $qameta, ap_qameta_fields() );

	$qameta['votes_net']  = $qameta['votes_up'] + $qameta['votes_down'];
	$qameta['activities'] = maybe_unserialize( $qameta['activities'] );

	if ( empty( $qameta['activities'] ) ) {
		$qameta['activities'] = array();
	}

	$qameta['fields'] = maybe_unserialize( $qameta['fields'] );
	$qameta           = (object) $qameta;

	return $qameta;
}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment