New answers tagged

0

Change the_field() to get_field() the_field() = echo get_field()


1

When you are concatenating string you shouldn't use ;after the method. Also you should close que quotes, call the method, and open again. Try the code below: $listItem .= '<div id="agenda-block-image-responsive" style="' .get_field('speaker-img' ) . '">';


0

date() PHP functions returns the value of time() PHP functions in the specified format. time() use server local time. If you want to get date/time based of WordPress configuration, you could use current_time(), a WordPress function, instead of native PHP functions. // 'timestamp' = Unix Timestamp or 'U' PHP time format $current_time = current_time( '...


0

I'd set up... Teams and Tournaments as taxonomies Players and Managers as post types. If you link the taxonomies to both post types you will be able to link both Players and Managers to the same Team or Tournament. CPT UI is a pretty good plugin to help create and manage custom post types.


0

$terms = get_terms( array( 'taxonomy' => 'category', 'hide_empty' => false, ) ); $sort = array(); //loop to list through all category foreach ( $terms as $term ) { $id = $term->ID; $name = $term->name; $args = array( 'post_type' =&...


0

You need an action called manage_$post_type_posts_custom_column. This will allow you to add columns to your custom posts page. To be more precise, you need a filter to generate the column and an action to fill it with content. In your case something like this (untested): add_filter( 'manage_chimpmunks_posts_columns', 'set_custom_size_column' ); add_action( '...


1

If i create an array and convert it into JSON, will it be faster if i call 12 meta fields one by one or call the JSON, parse it and then have the variables? Virtually no difference. The meta API means that all meta keys/fields/values are pulled into memory from the database at most once per post. So this: $keys = [ 'this', 'that', 'then' ]; $data = []; ...


0

Textareas behave quite different to text inputs in the browser rendering engine. I cannot figure out the use case of a single line textarea without scroll bars. If you want to copy the default text input behaviour to all effects, what is wrong with using a simple input type="text" instead for your custom field? If you intend to keep the textarea multiline ...


1

This is more about string and array manipulation with php than a WordPress related question. The proper way to do it would be using a repeater field instead of a single text input. Advanced Custom Fields, which seems to be the plugin you are using, has a nice repeater addon. That would let the users add as many fields as they want, change their order, ...


1

You probably need the NOT EXISTS meta_compare value. This will test if a meta value exists or not for that particular key. Also, as I pointed out in comments, caller_get_posts is long time deprecated, a notice you should have clearly recieved if you had debubbing turned on. The correct parameter is ignore_sticky_posts and accepts 0 (false) or 1 (true) ...


0

It's unclear from your question what the actual problem is; on a hunch, should it be this: if ( ! empty( $entries[ $key ]['newblock_url'] ) ) : ... instead of: if ( get_post_meta( $post->ID, 'newblock_url', true ) ) :


2

checked() will echo the result by default. That's the problem. To concat, you need to disable echo functionality by specify third param to false: echo '<input type="checkbox" id="my_meta_box_check1" name="my_meta_box_check1" ' . checked( $check, "on", false ) . '/>';


0

I found this approach to solve the problem of validate metabox fields using PHP code https://tommcfarlin.com/post-meta-data-error-messages/ Hope this help you (works for me in a similar scenario)


2

I don't know why you are using a custom template for displaying an individual Video post when there is a single file that is used for this purpose - single-{post_type}. https://codex.wordpress.org/Post_Type_Templates Using the single file, you will be able to get the post ID with $post->ID or get_the_ID(). if( have_posts() ) : while( have_posts() ) : ...


2

I would not use custom fields or shortcodes for this functionality, I would look at filters. the_content filter and the loop_end action (just make sure that your theme uses while ( have_posts() ) in single post pages) comes to immediate mind here. These are two options which requires no modification of any of your files in your theme. This way you can add ...


0

Were you showing all of your Custom Post Type "Video" post on a loop? Im not sure if your $video->ID matches with your CPT post id. Try Using get_the_ID() in place of $video->ID for reference: https://developer.wordpress.org/reference/functions/get_the_id/


1

Quickest way is actually to make a standalone php file (wrap the code in <?php CODE ?> and save it in your /wp-content/mu-plugins/ directory, eg, I often use a site-shortcodes.php... WordPress will auto-load the file, and your functionality will be independent of the theme you use. otherwise if the functionality is tied in to your theme specifically ...


1

The p parameter accepts a single integer value, not a string or array of integers. You would want to use the post__in parameter which allows for an array of post id's. Just a few notes here: You will need to check if you actually have a valid array of post ID's before passing it to post__in. If an empty array is passed, WP_Query fails epically in that it ...


0

Instead of do_shortcode you can use the run_shortcode function of $wp_embed global $wp_embed; $embed = $wp_embed->run_shortcode( '[embed]' . $url . '[/embed]' ); echo $embed;


2

We could also use one of the following filters, available since WordPress 4.2: pre_get_avatar_data get_avatar_url get_avatar_data Regarding how to get the user ID from the $id_or_email we can see how it's done in the core: $email_hash = ''; $user = $email = false; if ( is_object( $id_or_email ) && isset( $id_or_email->comment_ID ) ) { $...


3

As an alternative to my other answer, you can also use the get_avatar filter. Props to Sumit to alerting me to this one. The benefit of using the get_avatar filter is your custom avatar should be applied anywhere Wordpress uses it, rather than just in this users list like my other answer deals with. If you use plugins that display user avatars, this ...


1

EDIT: My original solution is below, but Sumit alerted me in the comments to the existence of the get_avatar filter. I've posted an additional answer that shows how to implement that option as well. Yes, you can do this. The columns displayed in any of these 'list tables' in Wordpress admin are filterable - so using a custom function in your theme's ...


1

There are three problems 1. echo and php tags within an echo Change your first echo from: echo '<img src="http://img.youtube.com/vi/<?php echo get_post_meta($post->ID,'video_url',true);?>/0.jpg"/>'; to this: echo '<img src="http://img.youtube.com/vi/' . get_post_meta($post->ID,'video_url',true) . '/0.jpg"/>'; 2. if statement ...


0

Adding another way here. You can leave this to WordPress and just pass the URL from the_content filter. Example:- $adresgoeshere = 'URL of oembed providers' echo apply_filters('the_content', $adresgoeshere);


3

You could encode them as JSON, or as serialized strings (the latter of which you can do using functions already baked in to Wordpress). Both of these options will let you keep the number of database rows down. However, both of these options will also significantly hamper your ability to search the data, or deal with it meaningfully in other ways if you need ...


2

As you are using URLs from oEmbed provides (YouTube, Vimeo, Soundcloud, etc), I would use wp_oembed_get() function. This function uses oEmbed and tries to get the embed HTML of the provided URL. $embed = wp_oembed_get( $some_url ); if( $embed ) { echo $embed; } else { // The embed HTML couldn't be fetched }


0

This is assuming each of the fields is a single value and you want to create a list for display... add_action('edit_post','custom_combine_fields'); function custom_combine_fields($post_id) { $pirates = get_post_meta($post_id,'pirates',true); $robots = get_post_meta($post_id,'robots',true); $ninjas = get_post_meta($post_id,'ninjas',true); $...


0

WordPress has remove_meta_box() function. You can use it to remove meta box like function remove_post_meta_box() { remove_meta_box( 'meta_box_id' , 'post' , 'normal' ); } add_action( 'admin_menu' , 'remove_post_meta_box' );


1

I've read through your post in it's entirety, I certainly don't see anything particularly wrong with it, but it sounds to me like your more frustrated with how it's been laid out. I personally have a big objected oriented programming background, it allows me to establish a structure and makes my code much more re-usable. My suggestion to you would be to ...


0

I recommend you look into the get_{$meta_type}_metadata filter. This is a basic hook setup to return a dynamic post meta value: <?php add_filter( "get_post_metadata", function( $points, $post_id, $meta_key, $single ){ if ( 'points' == $meta_key && $single ) { update_post_meta( $post_id, 'rank', calculate_post_rank( $post_id, $points ) ...


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" name="...


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 ...



Top 50 recent answers are included