Articles of post meta

get_post_meta fails after switch_to_blog

I have some code for custom cron in wordpress multisite, that from each blog site, gets their posts and postmeta data and put them on an xml structure. But, when I retrive metadata (using get_post_meta) from each blog (using switch_to_blog), I get the data from the principal site (blog_id=1) not from the site I would […]

Would this post meta be better added to the post table rather than post_meta table

I have a function that records the post views, and my post loops can be ordered by post views. This is the code: /** * Set Post views * */ function hp_global_set_post_views() { if (!is_single()) return; global $post; $post_id = $post->ID; $view_count = get_post_meta($post_id, ‘view_count’, true); $view_count++; update_post_meta($post_id, ‘view_count’, $view_count); } add_action(‘wp_head’, ‘hp_global_set_post_views’); /** example […]

Issue with using add_rewrite_rule() for post querying custom fields

Here’s what I’m trying to do. I made it so that the posts can store a postmeta value using a meta box textarea field. Here’s what I have done so far: I extract the meta value and explode it to an array on line breaks, so I can access each value using the keys on […]

How to separate posts in loop?

Let say I want to separete posts on how big or important they are. I want to set some kind of label on them so I can display them with different style. I want to create some values to choose from, like the post formats.. Should I create a custom taxonomy or custom fields? Or […]

How to create a shortcode to print specific values stored in a post meta array?

i am having problems printing a specific value stored in a post-meta array in a WordPress loop created by a Visual Composer Grid Builder, thru a shortcode (i also tried the grid builder Custom Field, but wasn’t able to find ANY examples). I tried adding this shortcode in functions.php: function dmc_prezzo() { $postid = get_the_ID(); […]

Doubts about the use of metadata and how this can affect performance on WordPress

I’m working on a project with some metadata inside loops like this: while( $query->have_post() ): the_post(); get_post_meta( postID, postMetakey, … ); endwhile; I’m using get_post_meta, i was wondering if i use get_post_meta() i’m making a new query to the database? So I’m increasing the processing time? if i use get_meta() all the data is there, […]

Unknown characters added to meta data values

I am trying to import post meta through the REST API. I have the meta value set on the parent site, but when I import the post to the child site there are additional characters added to the value. Here is the JSON representation of the post meta from the parent site: “post-meta-fields”: { “_edit_lock”: […]

How to create a meta_query to get all posts with a specific meta data?

Here are the args for my query : $args = array( ‘post_type’ => ‘product’, ‘posts_per_page’ => -1, ‘meta_query’ => array( array( ‘key’ => ‘vendor’, ‘value’ => ‘farsi’, ‘compare’ => ‘=’, ), ) ); This doesn’t work when topics is a string, it gets me all products, But I need to get all products that have […]

Set Condition echo function get_post_meta

I want to try echo marks of the specific quiz by name I have two quiz for each course. Quiz One Quiz Two I call a function to echo marks global $wpdb; $marks = get_post_meta($course_id,$member_id, true); echo $marks that’s print all marks for every quiz How I echo only Quiz One’s marks and table (Test […]

add_post_meta adds meta to one more different post

I am trying to save post meta when the post is viewed containing key userid:x with value of the current post’s ID. This information lets me know if the post has been read by current user (making notification in sidebar out of it afterwards). I do this by running this code in the loop of […]