New answers tagged

0

I think the problem might could be the logic with using checked... <input type="checkbox" name="aps_display_post_title" value="yes" <?php if ($aps_display_post_title != 'no') {echo 'checked';} ?> /> ...on the other hand then running sanitize_text_field on the checkbox value might also be causing the problem. Instead you might want to break ...


0

Your code will make the value yes only when the user fills the form. You could check if the meta is not there then make it checked, or try this: $aps_display_post_title = get_post_meta( $post->ID, 'aps_display_post_title', true ); $aps_display_post_title = ! ( 'off' == (string) $aps_display_post_title ); ?> <input type="checkbox" ...


0

ACF is a very good option, it has specific options to create user fields. There are tons of tutorials and practical examples out there, just google it and you will find them. It is one of the most popular WP plugins, so don't be afraid of compatibility problems, it's well maintained. You can check its documentation for practical examples about getting it ...


0

I think the sort is either alphabetical or numerical. There is no API way to provide more elaborate sorting rules to the query and messing with SQL for it would be likely impractical. Since you are retrieving complete set of posts (don't have to worry about pagination) the easiest way would be: Request no sort from query. Reā€“sort $the_query->posts set ...


-1

I found an solution that worked for me. I set up 9 regular posts (not custom post type's) in a clean wordpress install. In groups of three I created custom fields named meta_value. In groups of three, I set the values to road, air, bus. I tested your query and could see the trouble you were running into. After a few minutes of googling and going through ...


0

in_category relies on a global post - it should only be used within the loop. Instead, use the arguments that are passed to your callback to query the categories assigned to the post being edited and check if one of them is video: $cats = get_the_category( $post['ID'] ); if ( in_array( 'video', wp_list_pluck( $cats, 'slug' ) ) { // In "video" category } ...


0

You could have saved yourself a ton of work and just used the Co-Authors Plus plugin. It has a guest author function. You do have to set them up, but there is no account/password for them, and they can have author pages. (I am not affiliated with them, just use it on several sites.)


1

Try this, with " tags on .= '<a href="'.get_permalink($id).'"><img src="'.$image['url'].'" /></a>';


1

WP API has a rest_prepare_post filter (or rest_prepare_CPT if you are working with custom posts) which you can use to modify the JSON response. In your case it will be rest_prepare_joblisting. function filter_joblisting_json( $data, $post, $context ) { $phone = get_post_meta( $post->ID, '_phone', true ); if( $phone ) { $data->data['phone'] = ...


1

$post in the callback function is an array, not an object. So you cannot use $post->id. Change it to $post['id'] and it should work: function slug_get_phone_number($post, $field_name, $request) { return get_post_meta($post['id'], '_phone', true); } I recommend to change _phone to phone_number or something else without underscore prefix. Because _ ...


-1

if some one need take custom field by post type i leave the code below of the way I did and work fine for me :) function awh_field_type($post_id){ $awh_f_post = get_post_type($post_id); $meta_value = ''; $meta_name = 'custom'; if($awh_f_post == 'product'){ add_post_meta($post_id,$meta_name,$meta_value,true); } return $awh_f_post; } ...


0

I assume you're already properly using the WP Metadata API https://codex.wordpress.org/Metadata_API to attach the field to new comments and you just want to backfill for existing comments by stuffing the database? If it was my problem, I wouldn't bother and would assume in my code that absence of meta implied no likes. If you use update_meta_data() to ...


0

I use CMB2 to set up custom fields, and the logic is not so different from ACF in many cases. For my specific use case I've created a very simple but flexible function in order to make a few checks for the taxonomy before displaying the custom field value. Considering one have created a custom field named my_cf for let's say a taxonomy named basic as per ...


0

As already said, your query arguments are slightly off - meta_query should be an array of arrays: $query = new WP_Query( array( 'category_name' => 'events', 'order' => 'DESC', 'orderby' => 'meta_value', 'meta_query' => array( array( 'key' => 'start_date', 'value' => ...


0

I needed the code in functions.php so that I could re-use it. Here's my solution below: function get_img_alt($attachment) { $post = get_post(); $image_id = get_post_meta( $post->ID, $attachment, true ); $image_alt = get_post_meta($image_id, '_wp_attachment_image_alt', true); print $image_alt; }


0

In the end it was a plugin and my code conflicting with each other. Both were saving my post_meta. Resulting in odd behavior of my code and functionality of retrieving the data.


1

You can use current_user_can() and is_user_logged_in() to validate current user: <?php if ( is_user_logged_in() && current_user_can('role') ) : ?> <span style="font-size:16px"> <strong>Currently reading:</strong> <?php the_field('book_name'); ?> (<?php the_field('book_year'); ?>)<br/> ...


0

Herewith find the below answer for my own question for the custom taxonomies based listing the categories add_action( 'init', 'rest_custom_category_request', 25); function rest_property_type_category_request(){ global $wp_taxonomies; $wp_taxonomies['custom_category']->show_in_rest = true; $wp_taxonomies['custom_category']->rest_base = ...


0

You have a date format mismatch here. You say your dates are saved as Y/m/d in your custom field, which is correct, but then you try to match this format to unix timestamp (which is the result from time()). Date and time formats need to be in exactly the same format in order to match or to compare two different dates in a custom field, this is how custom ...


1

Technically, third party plugins are off-topic for this site. However this is an easy one - in the Custom Fields page in the admin area, go into your field group. Scroll right down to the bottom and there's a section allowing you to "hide" elements in the post. Select the "content" option here and you're done. Keep in mind that if you have multiple field ...


0

If I understand it right your workflow is that you query posts (implicitly via normal WP mechanics), then display data from external database for them, but want to sort based on external data. This isn't trivial (without mirroring you don't want to do), since WP relies primarily on SQL over its own data for sorting. One of the ways you could implement it ...


0

As suggested by @Sumit, the problem was in the template: there was a test that prevented the_content() to execute when the content was empty. <?php if ( $page->post_content && have_posts() ) while ( have_posts() ) : the_post(); ?> <?php the_content(); ?> <?php endwhile ?>


0

<?php // False: get all, true: get only first // Use false if you want to get all, if you have only one, it doesn't break $profile_twitter = get_post_meta( $post->ID, 'profiletwitter', false ); // Let's check if there's any if( ! empty( $profile_twitter ) ) { ?> <span class='social-profile'> <?php // Check if an array -> ...


0

You can order posts by meta value check out the codex https://codex.wordpress.org/Class_Reference/WP_Query


0

You will need to add custom query vars: add_filter('rest_query_vars', 'wpse225850_add_rest_query_vars'); function wpse225850_add_rest_query_vars($query_vars) { $query_vars = array_merge( $query_vars, array('meta_key', 'meta_value', 'meta_compare') ); return $query_vars; } Now, get your posts at ...


0

This question is more than 1 year old, but I have the same problomlem, and here is function that will add each meta_value and meta_key to $wp_query object, instead of query each post meta in while loop, this function will do One extra query example: "SELECT meta_key, meta_value, post_id FROM $wpdb->postmeta WHERE post_id IN (1,2,3,4,5...)" where ...


2

I can already tell that you're using ACF - if you don't want to change the return settings for the field, you can bypass ACF and just pull the image ID directly from post meta: $image_url = get_field( 'my_field_name' ); $image_id = get_post_meta( $post->ID, 'my_field_name', true ); $image_meta = wp_get_attachment_metadata( $image_id );


2

To do that, you'll need a custom query - Wordpress doesn't have a ready-made function for getting that type of data from the termmeta table. The custom query uses get_col() which allows you to get an array of the term_ids where the meta_key and the meta_value match the values you have in the question. Notice that the query uses prepare() which is good ...


1

You didn't add the save meta action for the facebook meta box. <?php /* Fire our meta box setup function on the post editor screen. */ add_action( 'load-post.php', 'sw_post_meta_boxes_setup' ); add_action( 'load-post-new.php', 'sw_post_meta_boxes_setup' ); /* Meta box setup function. */ function sw_post_meta_boxes_setup() { /* Add meta boxes on the ...


0

In your example, the 'Key Industries' page appears to be a different page under each of those top level menus - or at the very least, the URL is different. This most likely allows their CMS to differentiate and use the correct submenu. Here's what I do when I want to achieve this: Hook into wp_nav_menu_objects and check for a custom submenu argument, ...


2

As the keys already hold PHP generated output, it should be possible to simply wrap them in some MarkUp woocommerce_wp_select( array( 'id' => 'productstatus_select', 'label' => __( 'Product Status', 'woocommerce' ), 'options' => array( 'Message one' => sprintf( '<span ...


0

I hope I understand the question correctly UPDATE `wp_postmeta` SET `meta_value` = replace(meta_value, 'old_value', 'new_value') WHERE `meta_key` LIKE 'your_key' EDIT 1 : i forgot to mention : BACKUP YOUR DATABASE BEFORE ANY TRIAL EDIT 2 : following comment : To copy from one field to another (I got a bit confused with your naming and which value you ...


2

You can do in the following way! Create an array of CSS class names and message values $colors_stings = array( 'Message one' => 'message_color_green', 'Message two' => 'message_color_red', 'Message three' => 'message_color_blue' ); Check if message string exist in array then assign CSS color class to variable. $css_class = ...



Top 50 recent answers are included