Get post-meta value of all custom-posts – lowest to highest year-count?

something like this should do the job: global $post; $years = array(); $loop = new WP_Query( $args ); while ( $loop->have_posts() ) : $loop->the_post(); $this_year = get_post_meta( $post->ID, ‘event_date’, true ); if ( $this_year = date( ‘Y’, $this_year ) ) { if ( ! in_array( $this_year, $years ) ) { $years[] = $this_year; } } … Read more

Image upload and path to custom field

Found the solution. Forgot 2 lines of code. New is line 2 and line 11. I post the complete code: if( ‘POST’ == $_SERVER[‘REQUEST_METHOD’] && !empty( $_POST[‘action’] ) && $_POST[‘action’] == “new_post”) { $file=$_FILES; // Funktion zum Image-Upload, falls sie noch nicht existiert if ( ! function_exists( ‘wp_handle_upload’ )) { require_once(ABSPATH . “wp-admin” . ‘/includes/image.php’); … Read more

Run Function if Order Meta Exists – WooCommerce

WooCommerce orders are posts and behave the same as any WordPress post. So you can use the same WordPress functions to update or read the post meta data. <?php $meta_values = get_post_meta($post_id, $key, $single); ?> For your example I’d suggest: $match_order_meta = get_post_meta( $order->ID, ‘My_Checkbox’, TRUE); The ‘TRUE’ flag tells WordPress to return the value … Read more

Custom metabox not working

Problem #1: First problem: inside home-meta.php, pull all of your add_meta_box() calls outside of the add_meta_boxes_home() callback, and get rid of the callback and add_action() call. You handle this already, with the add_meta_boxes_page callback in functions.php, that includes home-meta.php. Problem #2: Warning: Invalid argument supplied for foreach() in /Users/[my_mac]/Sites/[site_dir]/wp-content/themes/[site_theme]/metaboxes/home-meta.php on line 224 Assuming that this … Read more

custom header text

For something like this, you can use WordPress’s built-in “Custom Fields” feature. Step 1 On your edit page, create a new Custom Field (if you don’t see the Custom Fields box on your edit screen, click on the grey”Screen Options” tab at the top-right of the page, and make sure the “Custom Fields” box is … Read more

Excerpt length: get first paragraph

Assuming your paragraphs are marked with <p> tags, which can be set in the ACF field options, the following should work: function custom_field_excerpt() { global $post; $text = get_field(‘news’); if ( ” != $text ) { $start = strpos($text, ‘<p>’); // Locate the first paragraph tag $end = strpos($text, ‘</p>’, $start); // Locate the first … Read more

KEY and VALUE custom field issue

I don’t know if you can count on the order of both custom fields to be equal when returned from get_post_meta(), but if you can, you could use: $links = get_post_meta($post->ID, ‘links’, false); $URLs = get_post_meta($post->ID, ‘URLs’, false); for ( $i = 0; $i < count( $links ); $i++ ) { if ( empty( $URLs[$i] … Read more

Custom Theme Fields in Settings Menu – apply filters to one of those fields?

You can create a custom filter using filter functions of Plugin API. I have changed you code as following to create and use custom filter. function add_gcf_interface() { add_options_page(‘Other’, ‘Other’, ‘8’, ‘functions’, ‘otherGlobalOptions’); } function otherGlobalOptions() { ?> <div class=”wrap”> <h2>Sonstiges</h2> <form method=”post” action=”options.php”> <?php wp_nonce_field(‘update-options’) ?> <p><strong>Welcome Message</strong><br /> <textarea name=”welcomemessage” cols=”100%” rows=”7″><?php echo … Read more

Add Custom Fields After Page Title

Use get_post_meta() in the theme template you want to modify. Like so… <h1>If This Were Your Page Title</h1> <?php echo get_post_meta(get_the_ID(), ‘Your Custom Field Name’, true); ?> Easy peasy. 🙂