Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use of meta_key_search #176

Open
manuelcanonad opened this issue Sep 6, 2021 · 5 comments
Open

Use of meta_key_search #176

manuelcanonad opened this issue Sep 6, 2021 · 5 comments

Comments

@manuelcanonad
Copy link

Hi!

I'm trying to use the meta_key_search parameter to show the meta value of a publication, but I do not know how it is used. my code is the following:

$args = meta_key_search => array( 'tp_meta_pub_custom_label' => '{Health}' )

        echo $args;

        $array = TP_Publications::get_publications( $args, $count = false );

Thanks!!

@winkm89
Copy link
Owner

winkm89 commented Sep 7, 2021

Hi,
I think the correct code should be this. Please note: tp_meta_pub_custom_label is a placeholder for the ID of the custom field, which is displayed in the meta data screen for publications.

$args = array(
            'meta_key_search'       => array( 'tp_meta_pub_custom_label' => '{Health}' )
        );
$output = TP_Publications::get_publications( $args );

@manuelcanonad
Copy link
Author

Hi Michael,

Thank you so much for your help!

I would like to know if I can to put into a shortcode any value of a metadata like the ID or the metadata name.

Thanks!

@manuelcanonad
Copy link
Author

Hi Michael!

Another question is the next: I want to put into your code a variable like this:

$args = array(
'meta_key_search' => array( 'tp_meta_pub_areas_de_investigacion' => $metadata )
);

But It doesn´t work. How can I get it?

THANKS in advance!

@winkm89
Copy link
Owner

winkm89 commented Sep 14, 2021

It should work if $metadata contains the correct form for the value, you want to find. That's something I forgot in the first post:

// If your custom field is a CHECKBOX: The value must enclosed by curly brackets 
$metadata = '{Demo Value}';
// For all others this isn't necessary
$metadata = 'Demo Value';

// Your search
$args = array( 'meta_key_search'  => array( 'tp_meta_pub_custom_label' => $metadata ) );

Please note in addition, that this meta key search is currently only a "is equal search" over the field "meta_value" in the table "teachpress_pub_meta".

@shahab-ab
Copy link

shahab-ab commented Nov 1, 2021

Hi Michael,
could you offer an optimal way to include meta_key_search in your shortcodes as well? or do you have any plan to implement it?

Actually there is no way currently - but I have added two separate arrays in the main shortcodes atts for keys and values with commas between array items then exploding them into the array of your meta_key_search. (as there can be more than one meta key)
meta_keys('key1', 'key2')
meta_val('val1', 'val2')

meta_key_search('key1'=>'val1', 'key2'=>'val2')

These customizations are always lost while update. Therefore it would be great if it is included by default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants