Articles of custom field

Custom post types category

I have created a theme with a custom post type called ‘project’ and there is a problem. I want to show 5 different custom post type categories on a page in different portions, like posts to show on pages from their respective categories. Is there any solution? This is my custom post type code with […]

Sorting posts by Multiple custom fields in defined order

I’m currently sorting some posts out by custom fields ‘role’ and ‘surname’, using the following: function customorder($orderby) { return ‘mt1.meta_value DESC, mt2.meta_value ASC’; } $args = array( ‘post_type’ => ‘staff’, ‘meta_key’ => ‘role’, ‘meta_query’ => array( array( ‘key’ => ‘role’ ), array( ‘key’ => ‘surname’, ), ) ); add_filter(‘posts_orderby’,’customorder’); $query = new WP_Query( $args ); […]

How can I store data from custom fields to custom tables?

I know how to make custom fields for my custom post types. I also know there is the Advanced Custom Fieldsplugin. But I need to know how I can store my custom fields in my custom post type to my custom DB tables. I’ve been looking for tutorials, but I only find how to create […]

How to use conditional statement with custom field

I think it is a simple thing but I am not good on php so 🙁 can you guys tell me how I can use an if condition with my custom filed. Below is my current code. <div class=”courtesy”><?php echo post_custom(‘courtesy’); ?></div> I want courtesy to show if it has a value. Right now if […]

Custom field php

Hi I put this php code on my single post php <?php $custom_fields = get_post_meta($post_id); $my_custom_field = $custom_fields[‘_source_link’]; //key name foreach ( $my_custom_field as $key => $value ) echo $key . ” => <a href='” . $value . “‘>Click Here</a><br />”; ?> however I’ve got error Warning: Invalid argument supplied for foreach() How to fix […]

get posts where a custom field contains a text

I have a custom field where the value contains a comma separated list of items (like: test1,test2,test3), now I want to retrieve posts where the field contains one of the values, I have: $query = get_posts( array( ‘post_type’ => ‘custom_post’, ‘posts_per_page’ => 11, ‘meta_query’ => array( array( ‘key’ => ‘_my_custom_field_key’, ‘value’ => array(‘test1’), ‘compare’ => […]

Is there a way to dump all registered sidebar/widget?

I need to know the properties of sidebar and widgets I’ve added, is there a way to dump those? Thanks.

Why am I getting a “Call to member function format() on a non-object” error?

I am trying to add a hook to post saving using WP Frontend User When the form saves and the post is created within the “save_post” function I am trying to find the value of a custom field “cf_end_date” and assign it to something else I am not able to grab the custom field “cf_end_date” […]

WP_Query Meta_key is text value and need to sort as numeric not working

I have the following code below in my ~WP_Query`. $args[ ‘meta_key’] = ‘price’; $args[‘orderby’] = ‘meta_value meta_value_num’; $args[‘order’] = ‘ASC’; The custom field in question has historic data that was created in a custom field and set as text. When I run my query I get the following results: 1,199.00, 1,299.99 169.99, 379.95. which looks […]

Fill empty custom field with other custom field

i have a product listing website, all products are uploaded from csv. i have a two custom field named “old_price” and “new_price”. Sometimes there is no discount (new_price) , so the field be empty. i would like to store the value of “old_price” in “new_price” , If “new_price” is empty. its important that it get […]