For a woocommerce plugin to filter global attribute terms and custom fields, I need to set up the meta_key and the meta_value.
I tried to find out which these exactly are:
I tried:
meta_key=’pa_attribute’, meta_value=’1 Value’
meta_key=’pa_attribute’, meta_value=’1-value’
meta_key=’_pa_attribute’, meta_value=’1 Value’
meta_key=’_pa_attribute’, meta_value=’1-value’
I checked any possible combination, but could not get to work.
I also need the meta_key and the meta_value from postmeta.
Does anyone know how to do this?
What is the exact syntax for these terms?
Thanks
Related
I have more than one category name in the post and I want to change specific primary category name to be normal category and then normal category to be primary category.
Let's say I have sponsored category and fashion category. So, I want to switch fashion category to be primary category because I do not want to show /sponsored/ in the URL.
Take Note: I have thousand of posts and I cannot switch the category name manually.
Using SQL and PHP you can run a foreach loop with all posts id that need to be updated.
A good starting point is an Excel file with all posts and its category ids that will be set as primary, so convert the spreadsheet to a json file to use in the PHP loop.
Below is the SQL query to do this:
UPDATE wp_postmeta SET meta_value = $new_primary_id WHERE post_id = $post_id AND meta_key = '_yoast_wpseo_primary_category';
Where $new_primary_id is the id of the category that will be set as primary, and $post_id
is the post id that will be updated.
If you using Yoast SEO Plugin there is the solution for you check here.
https://wordpress.org/support/topic/bulk-change-primary-category/
I'm using
<?php query_posts('cat=34546&posts_per_page=5&order=DESC');
in order to get five posts from a certain category. The order is determined by the ID of the post. I would like it to be determined by another field, like post_date column in posts (let's say for the sake of this question that I manually change post_date that in the database). How can this be done?
Using the Query Posts orderby parameters.
https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters
For example:
<?php query_posts('cat=34546&posts_per_page=5&order=DESC&orderby=date');
The reference I linked above has what values you can use for orderby.
How can one reset the number of post views in order to remove a specific page from appearing in the "Popular" pages Wordpress widget?
Late to the party, I know, but I needed to figure this out today, which I did. So in case anyone else needs to know (for reference, I'm running WordPress version 3.3.1):
Page views are stored in the wp_postmeta table with a meta_key of post_views_count. Here's the query I used to find the views of a single post:
SELECT * FROM 'wp_postmeta' WHERE 'meta_key' = 'post_views_count' AND 'post_id' = 1234
The query returned 2 results. I'm not sure why, but setting the meta_value of both to zero did the job for me.
In the Wordpress Media Library, when you add a piece of media, you're invited to also add other 'metadata': Title, Caption, Alternate Text, and Description.
Using get_the_title() will return the title, but trying get_the_caption() simply breaks the page.
How do I get this data, or metadata on the page. I've also tried using wp_get_attachment_metadata(), which returns an array. Does anyone know what values are in this array? I know it has height and width.
I see that this metadata is stored to the wp_posts table. For example, the caption for a photo is in column post_excerpt. Since the title column is post_title, you might want to try the same naming convention and try a call to get_the_excerpt(). Here are the other names of the columns in the wp_posts table
post_author post_date post_date_gmt post_content post_title post_excerpt post_status comment_status ping_status post_password post_name to_ping pinged post_modified post_modified_gmt post_content_filtered post_parent guid menu_order post_type post_mime_type comment_count
Hope this helps
I have about 100 posts in wordpress, all with a meta_key of price and a value.
How would I go about searching through all posts with a value between 23.00 and 41.00 for example?
I know that 'meta_compare ' treats 'meta_value' as a string, so I can't use this to solve my problem. Anybody have any clues? Thanks
I would try to implement the posts_where filter, and modify the query there. It gets called right after the meta comparison is added, and it allows you to change the WHERE part of your query. You need to replace all instances of your meta key to CAST(meta_key AS DECIMAL(5,2)). I guess the meta key is prefixed by the meta table name, so check for that. You will need to figure out a way to pass two meta_value parameters if you want to do a BETWEEN query, but you can combine them with a comma and split them up in your filter. As long as a valid SQL where-clause comes out of you filter, everything should work.