function property_post_list() { $propid_array = array(); $args = array('numberposts' => -1, 'meta_key' => 'property_id'); $posts_array = get_posts($args); if (count($posts_array) > 0) { foreach ($posts_array as $p) { //print_r($posts_array);exit(); $propid = get_post_custom_values('property_id', $p->ID); if (!empty($propid)) { $prop_array[$p->ID] = $propid; } } } ?> <script> var prop_post_array = new Array(); <?php foreach ($prop_array as $po => $pr) { ?> prop_post_array[<?php echo $pr[0]; ?> ] = <?php echo $po; ?> ; <?php } ?> </script> <?php }
function ktz_jsscripts() { global $is_IE, $post; if (!is_admin()) { if (is_object($post)) { $ktz_self_video_youtube_mt = get_post_custom_values('ktz_youtube_id', $post->ID); $ktz_self_video_vimeo_mt = get_post_custom_values('ktz_vimeo_id', $post->ID); $ktz_self_video_dailymotion_mt = get_post_custom_values('ktz_dailymotion_url', $post->ID); global $post; $meta_values = get_post_custom($post->ID); } if (is_singular()) { wp_enqueue_script('comment-reply'); } wp_enqueue_script('modernizr-respon'); wp_enqueue_script('ktz-jsscript-js'); wp_enqueue_script('ktz-rating-js'); if (is_single() && has_post_format('video')) { wp_enqueue_script('ktz-video-js'); } if (is_single() && $ktz_self_video_youtube_mt && has_post_format('video')) { wp_enqueue_script('ktz-video-youtube-js'); } if (is_single() && $ktz_self_video_vimeo_mt && has_post_format('video')) { wp_enqueue_script('ktz-video-vimeo-js'); } if (is_single() && $ktz_self_video_dailymotion_mt && has_post_format('video')) { wp_enqueue_script('ktz-video-dailymotion-js'); } wp_enqueue_script('ktz-main-js'); wp_localize_script('ktz-rating-js', 'ktz_ajax_data', array('ajax_url' => admin_url('admin-ajax.php'), 'codes' => array('SUCCESS' => 1, 'PREVIOUSLY_VOTED' => 0, 'REQUEST_ERROR' => 2, 'UNKNOWN' => -1), 'messages' => array('success' => __('You\'ve voted correctly', ktz_theme_textdomain), 'previously_voted' => __('You had previously voted', ktz_theme_textdomain), 'request_error' => __('The request was malformed, try again', ktz_theme_textdomain), 'unknown' => __('An unknown error has occurred, try to vote again', ktz_theme_textdomain)))); } }
function wp_ozh_yourls_newpost($post) { global $wp_ozh_yourls; $post_id = $post->ID; $url = get_permalink($post_id); if ($post->post_type != 'post' && $post->post_type != 'page') { return; } // Generate short URL ? if (!wp_ozh_yourls_generate_on($post->post_type)) { return; } $title = get_the_title($post_id); $url = get_permalink($post_id); $short = wp_ozh_yourls_get_new_short_url($url); // Tweet short URL ? if (!wp_ozh_yourls_tweet_on($post->post_type)) { return; } if (!get_post_custom_values('yourls_tweeted', $post_id)) { // Not tweeted yet $tweet = wp_ozh_yourls_maketweet($short, $title); if (wp_ozh_yourls_send_tweet($tweet)) { update_post_meta($post_id, 'yourls_tweeted', 1); } } }
function post_thumbnail_src() { global $post; if ($values = get_post_custom_values("thumb")) { //输出自定义域图片地址 $values = get_post_custom_values("thumb"); $post_thumbnail_src = $values[0]; } elseif (has_post_thumbnail()) { //如果有特色缩略图,则输出缩略图地址 $thumbnail_src = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'full'); $post_thumbnail_src = $thumbnail_src[0]; } else { $post_thumbnail_src = ''; ob_start(); ob_end_clean(); $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches); $post_thumbnail_src = $matches[1][0]; //获取该图片 src if (empty($post_thumbnail_src)) { //如果日志中没有图片,则显示随机图片 $random = mt_rand(1, 10); echo get_bloginfo('template_url'); echo '/images/random/' . $random . '.jpg'; //如果日志中没有图片,则显示默认图片 //echo '/images/default_thumb.jpg'; } } echo $post_thumbnail_src; }
function tumblrLinkBacks($content) { global $wp_query, $post; $post_id = get_post($post->ID); $posttitle = $post_id->post_title; $permalink = get_permalink(get_post($post->ID)); $tumblr_keys = get_post_custom_keys($post->ID); if (get_post_meta($wp_query->post->ID, 'TumblrURL', true)) { if ($tumblr_keys) { foreach ($tumblr_keys as $tumblr_key) { if ($tumblr_key == 'TumblrURL') { $tumblr_vals = get_post_custom_values($tumblr_key); } } if ($tumblr_vals) { if (is_feed()) { $content .= '<p><a href="' . $tumblr_vals[0] . '" title="Direct link to featured article">Direct Link to Article</a> — '; $content .= '<a href="' . $permalink . '">Permalink</a></p>'; return $content; } else { return $content; } } } } else { $content = $content; return $content; } }
function AB_external_permalink($permalink) { global $post; $thePostID = $post->ID; $internal_post = get_post($thePostID); $title = $internal_post->post_title; $post_keys = array(); $post_val = array(); $post_keys = get_post_custom_keys($thePostID); if (!empty($post_keys)) { foreach ($post_keys as $pkey) { if ($pkey == 'original_source') { $post_val = get_post_custom_values($pkey, $thePostID); break; } } if (empty($post_val)) { $link = $permalink; } else { $link = $post_val[0]; } } else { $link = $permalink; } return $link; }
/** * Adds the custom actions to the Commits list. * @access public * @param array $actions The default array of actions. */ public function custom_actions($actions) { if (get_post_type() == 'revisr_commits') { if (isset($actions)) { unset($actions['edit']); unset($actions['view']); unset($actions['trash']); unset($actions['inline hide-if-no-js']); $id = get_the_ID(); $url = get_admin_url() . 'post.php?post=' . get_the_ID() . '&action=edit'; $actions['view'] = "<a href='{$url}'>" . __('View', 'revisr') . "</a>"; $branch_meta = get_post_custom_values('branch', get_the_ID()); $db_hash_meta = get_post_custom_values('db_hash', get_the_ID()); $backup_method = get_post_custom_values('backup_method', get_the_ID()); $commit_hash = Revisr_Git::get_hash($id); $revert_nonce = wp_nonce_url(admin_url("admin-post.php?action=process_revert&commit_hash={$commit_hash}&branch={$branch_meta[0]}&post_id=" . get_the_ID()), 'revert', 'revert_nonce'); $actions['revert'] = "<a href='" . $revert_nonce . "'>" . __('Revert Files', 'revisr') . "</a>"; if (is_array($db_hash_meta)) { $db_hash = str_replace("'", "", $db_hash_meta); if (isset($backup_method) && $backup_method[0] == 'tables') { $revert_db_nonce = wp_nonce_url(admin_url("admin-post.php?action=revert_db&db_hash={$db_hash[0]}&branch={$branch_meta[0]}&backup_method=tables&post_id=" . get_the_ID()), 'revert_db', 'revert_db_nonce'); } else { $revert_db_nonce = wp_nonce_url(admin_url("admin-post.php?action=revert_db&db_hash={$db_hash[0]}&branch={$branch_meta[0]}&post_id=" . get_the_ID()), 'revert_db', 'revert_db_nonce'); } if ($db_hash[0] != '') { $actions['revert_db'] = "<a href='" . $revert_db_nonce . "'>" . __('Revert Database', 'revisr') . "</a>"; } } } } return $actions; }
function get_post_thumb($post_id, $width, $height, $custom = "image") { //universal thumb function $show_no_image = get_option("bordeaux_show_first_thumb"); $custom_image = get_post_custom_values($custom, $post_id); //get custom field value $custom_image = $custom_image[0]; if ($custom_image == "" && $custom != "image") { $custom = "bordeaux_slider_image"; $custom_image = get_post_custom_values($custom, $post_id); //get custom field value $custom_image = $custom_image[0]; } $meta = get_post_meta($post_id, "_thumbnail_id", true); //get wordpress built in thumbnail value $first_from_post = get_first_image($post_id); //get first image form post if ($custom_image != "") { //custom field value $file = $custom_image; if (strpos($file, "wp-content") !== false) { $pos = strpos($file, "/wp-content"); $file = substr($file, $pos); } $src = get_template_directory_uri(); $src .= "/timthumb.php?src="; $src .= $file; $src .= "&w={$width}&h={$height}&zc=1&q=100"; $show_image = true; } elseif ($meta) { //built in thumb $file = site_url() . "/wp-content/uploads/" . get_post_meta($meta, "_wp_attached_file", true); $src = get_template_directory_uri(); $src .= "/timthumb.php?src="; $src .= $file; $src .= "&w={$width}&h={$height}&zc=1&q=100"; $show_image = true; } elseif ($first_from_post != false && $custom != "bordeaux_slider_image") { //first attached image $file = $first_from_post; if (strpos($file, "wp-content") !== false) { $pos = strpos($file, "/wp-content"); $file = substr($file, $pos); } $src = get_template_directory_uri(); $src .= "/timthumb.php?src="; $src .= $file; $src .= "&w={$width}&h={$height}&zc=1&q=100"; $show_image = true; } else { //no image $src = get_template_directory_uri() . '/images/no-image-' . $width . 'x' . $height . '.jpg'; if ($show_no_image == "on") { $show_image = true; } else { $show_image = false; } } return array("src" => $src, "show" => $show_image); }
function cs_external_permalink($permalink) { global $post; $thePostID = $post->ID; $post_id = get_post($thePostID); $title = $post_id->post_title; $post_keys = array(); $post_val = array(); $post_keys = get_post_custom_keys($thePostID); if (!empty($post_keys)) { foreach ($post_keys as $pkey) { if ($pkey == 'url1' || $pkey == 'title_url' || $pkey == 'url_title' || $pkey == 'external') { $post_val = get_post_custom_values($pkey); } } if (empty($post_val)) { $link = $permalink; } else { $link = $post_val[0]; } } else { $link = $permalink; } return $link; }
function format_custom_field($field, $format = '', $date_format = 'F j, Y') { $fetch = get_post_custom_values($field); $fetch = $fetch[0]; // Test if anything was fetched or return false. if (!$fetch) { return false; } switch ($format) { case 'date': return date($date_format, $fetch); break; case 'text_block': return wpautop($fetch); break; case 'link': return '<a href="' . $fetch . '" class="custom_link">' . $fetch . '</a>'; break; case 'html': return html_entity_decode($fetch); break; case 'google_map': return display_google_map($fetch); break; default: // If you're not processing(formatting) the var at all // why even use this function? Just use the WP custom field funcs. return $fetch; } }
/** * Get the current page template * * Get the current page template in use. * * @since 4.0 * * @package WooFramework * @subpackage Template */ function woo_get_page_template() { global $wp_query; $page = $wp_query->get_queried_object(); $custom_fields = get_post_custom_values('_wp_page_template', $page->ID); $page_template = $custom_fields[0]; return $page_template; }
function cftpb_get_term_custom_values($term_id, $taxonomy, $key) { $return_val = null; $term_post = cf_taxonomy_post_type_binding::get_term_post($term_id, $taxonomy); if (!empty($term_post) && !is_wp_error($term_post)) { $return_val = get_post_custom_values($key, $term_post->ID); } return $return_val; }
function custom_field($field, $post_id) { $cf = get_post_custom_values($field, $post_id); if (count($cf) > 1) { return $cf; } else { return array_shift($cf); } }
function ta_modified_post_title($title) { if (in_the_loop() && !is_page()) { $title_word_count = get_post_custom_values('wc_the_word_count'); if ($title_word_count) { $title = $title . ' (Word Count: ' . $title_word_count[0] . ')'; } } return $title; }
function get_reservation_page() { $pages = get_pages(); foreach ($pages as $p) { $meta = get_post_custom_values("_wp_page_template", $p->ID); if ($meta[0] == "template-reservations.php") { return $p->ID; } } return false; }
function ktz_posted_title_a() { global $post; // post format link $ktz_link_pf = get_post_custom_values('ktz_link_postformat', $post->ID); if ($ktz_link_pf && has_post_format('link')) { printf(__('<a href="%1$s" title="External link to %2$s" rel="nofollow" target="_blank"><span class="glyphicon glyphicon-link"></span> %3$s</a>', ktz_theme_textdomain), esc_url($ktz_link_pf[0]), esc_url($ktz_link_pf[0]), esc_attr(get_the_title())); } else { // standard post format printf(__('<a href="%1$s" title="Permalink to %2$s" rel="bookmark">%3$s</a>', ktz_theme_textdomain), esc_url(get_permalink()), esc_attr(get_the_title()), esc_attr(get_the_title())); } }
function is_linked_list() { // global $wp_query; // $postid = $wp_query->post->ID; // $url = get_post_meta($postid, 'linked_list_url', true); $url = get_post_custom_values('linked_list_url'); if (!empty($url)) { $GLOBALS['dfllCustomFieldValue'] = $url; return true; } return false; // return (!empty($url)); }
function get_newspapermeta($field, $echo = 1, $before = '', $after = '') { $newspapermeta = get_post_custom_values('_newspapermeta_fields', $post->ID); $fields = unserialize($newspapermeta[0]); if ($fields[$field] !== NULL) { $output = $fields[$field]; if ($echo == 0) { return $output; } else { echo $before . $output . $after; } } }
static function copy_meta_info($new_id, $old_id) { $post_meta_keys = get_post_custom_keys($old_id); if (empty($post_meta_keys)) { return; } foreach ($post_meta_keys as $meta_key) { $meta_values = get_post_custom_values($meta_key, $old_id); foreach ($meta_values as $meta_value) { $meta_value = maybe_unserialize($meta_value); update_post_meta($new_id, $meta_key, $meta_value); } } }
function alimir_cfn() { if (get_post_custom_values('warning') || get_post_custom_values('information') || get_post_custom_values('success') || get_post_custom_values('failure') || get_post_custom_values('lightbulb') || get_post_custom_values('messages')) { $string = ''; $string .= '<div class="notification_container" style="margin-top:20px;">'; $warning = get_post_meta(get_the_ID(), 'warning', true); if (get_post_custom_values('warning')) { $string .= '<div class="notification ' . wp_cfn_theme() . 'warning hideit">'; $string .= '<p>' . $warning . '</p>'; $string .= '</div>'; } $string .= '<div class="notification_container" style="margin-top:20px;">'; $information = get_post_meta(get_the_ID(), 'information', true); if (get_post_custom_values('information')) { $string .= '<div class="notification ' . wp_cfn_theme() . 'information hideit">'; $string .= '<p>' . $information . '</p>'; $string .= '</div>'; } $string .= '<div class="notification_container" style="margin-top:20px;">'; $success = get_post_meta(get_the_ID(), 'success', true); if (get_post_custom_values('success')) { $string .= '<div class="notification ' . wp_cfn_theme() . 'success hideit">'; $string .= '<p>' . $success . '</p>'; $string .= '</div>'; } $string .= '<div class="notification_container" style="margin-top:20px;">'; $failure = get_post_meta(get_the_ID(), 'failure', true); if (get_post_custom_values('failure')) { $string .= '<div class="notification ' . wp_cfn_theme() . 'failure hideit">'; $string .= '<p>' . $failure . '</p>'; $string .= '</div>'; } $string .= '<div class="notification_container" style="margin-top:20px;">'; $lightbulb = get_post_meta(get_the_ID(), 'lightbulb', true); if (get_post_custom_values('lightbulb')) { $string .= '<div class="notification ' . wp_cfn_theme() . 'lightbulb hideit">'; $string .= '<p>' . $lightbulb . '</p>'; $string .= '</div>'; } $string .= '<div class="notification_container" style="margin-top:20px;">'; $messages = get_post_meta(get_the_ID(), 'messages', true); if (get_post_custom_values('messages')) { $string .= '<div class="notification ' . wp_cfn_theme() . 'messages hideit">'; $string .= '<p>' . $messages . '</p>'; $string .= '</div>'; } return $string; } }
/** * Copies post meta data * @param int $oldId * @param int $newId * @return boolean */ protected function cloneMeta($oldId, $newId) { $metaKeys = get_post_custom_keys($oldId); if (empty($metaKeys)) { return false; } foreach ($metaKeys as $metaKey) { $metaValues = get_post_custom_values($metaKey, $oldId); foreach ($metaValues as $metaValue) { $metaValue = maybe_unserialize($metaValue); update_post_meta($newId, $metaKey, $metaValue); } } return true; }
function get_custom_thumbnail($post) { $values = get_post_custom_values("Image"); if (has_post_thumbnail()) { $image_url = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'full'); } elseif (isset($values[0])) { $image_url = home_url('/') . $values[0]; } else { $image_url = bloginfo('template_directory') . '/images/blank.png'; } if (is_array($image_url)) { $image_url = $image_url[0]; } return $image_url; }
function traer_contenido_obra() { if (isset($_POST['cual'])) { $args = array('numberposts' => 1, 'include' => $_POST['cual']); $obra = get_posts($args); foreach ($obra as $post) { setup_postdata($post); $ingles = get_post_custom_values('contenido_en_ingles', $_POST['cual']); $izq = get_post_custom_values('columna_izquierda', $_POST['cual']); ?> <div class="lienzo clearfix <?php if ($ingles) { print_r('dos_columnas'); } ?> "> <?php the_content(); ?> <?php if ($ingles) { $contenido_ingles = $ingles[0]; $contenido_ingles = nl2br($contenido_ingles); $contenido_izq = $izq[0]; $contenido_izq = nl2br($contenido_izq); ?> <div class="columna izq"> <?php echo $contenido_izq; ?> </div> <div class="columna der"> <?php echo $contenido_ingles; ?> </div> <?php } ?> </div> <?php } } die; }
public function widget($args, $instance) { $title = apply_filters('widget_title', $instance['title']); $details = apply_filters('widget_details', $instance['details']); $category = apply_filters('widget_category', $instance['category']); $itemnum = apply_filters('widget_itemnum', $instance['itemnum']); echo $args['before_widget']; if (!empty($title)) { echo $args['before_title'] . $title . $args['after_title']; } if (!empty($details)) { echo '<p>' . $details . '</p>'; } if ($category == -1) { $loop = new WP_Query(array('post_type' => 'portfolio', 'posts_per_page' => $itemnum)); } else { $loop = new WP_Query(array('post_type' => 'portfolio', 'posts_per_page' => $itemnum, 'tax_query' => array(array('taxonomy' => 'portfoliocategory', 'field' => 'name', 'terms' => array($category))))); } $output = '<div class="cn_pf_widget_content"><div id="cn_pf_widget">'; if ($loop) { while ($loop->have_posts()) { $loop->the_post(); $portfolio_url = get_post_custom_values('_url'); if (preg_match("/\\b(?:(?:https?|ftp):\\/\\/|www\\.)[-a-z0-9+&@#\\/%?=~_|!:,.;]*[-a-z0-9+&@#\\/%=~_|]/i", $portfolio_url[0])) { $purl = parse_url($portfolio_url[0]); if (!isset($purl['scheme'])) { $purl = 'http://' . $portfolio_url[0]; } else { $purl = $portfolio_url[0]; } } else { $purl = $portfolio_url[0]; } $output .= '<div class="cn-single-portfolio">'; $url = wp_get_attachment_url(get_post_thumbnail_id()); if (!empty($portfolio_url[0])) { $output .= '<a href="' . $purl . '" class="cnprotfolio-img" target="_blank">'; } else { $output .= '<a href="javascript:void(0)" class="cnprotfolio-img">'; } $output .= '<img src="' . $url . '" alt="' . get_the_title() . '" />'; $output .= '</a></div>'; } } $output .= "</div></div>"; echo $output; echo $args['after_widget']; }
function autoset_featured_image() { global $post; $no_featured_image = get_post_custom_values('no_featured_image', $post->ID); if (empty($no_featured_image[0])) { $already_has_thumb = has_post_thumbnail($post->ID); if (!$already_has_thumb) { $attached_image = get_children("post_parent={$post->ID}&post_type=attachment&post_mime_type=image&numberposts=1"); if ($attached_image) { foreach ($attached_image as $attachment_id => $attachment) { set_post_thumbnail($post->ID, $attachment_id); } } } } }
/** * @param int $original_post * @param int $destination_post * * @return void */ public function copy_meta($original_post, $destination_post) { $this->clear_meta($destination_post); $post_meta_keys = get_post_custom_keys($original_post); if (empty($post_meta_keys)) { return; } $meta_blacklist = $this->get_meta_key_whitelist($original_post); $meta_keys = array_diff($post_meta_keys, $meta_blacklist); foreach ($meta_keys as $meta_key) { $meta_values = get_post_custom_values($meta_key, $original_post); foreach ($meta_values as $meta_value) { $meta_value = maybe_unserialize($meta_value); add_post_meta($destination_post, $meta_key, $meta_value); } } }
/** * Este é um método simples que irá exibir o texto do nosso shortcode */ public function banner_slider() { echo '<div class="banner cycle-slideshow " id="banner"> <div class="cycle-pager"></div> <div class="cycle-prev"></div> <div class="cycle-next"></div>'; $args = array('post_type' => 'banner', 'posts_per_page' => 4); $loop = new WP_Query($args); while ($loop->have_posts()) { $loop->the_post(); $valor = get_post_custom_values('rel'); $return_string = the_post_thumbnail('banner-slider', array('rel' => $valor[0])); } echo '</div>'; wp_reset_query(); return $return_string; }
function cpMenu($args = '') { $include_IDs = get_post_custom_values('custom-pages'); if (isset($include_IDs[0])) { $include_IDs = $include_IDs[0]; } else { $include_IDs = 'None'; } $defaults = array('depth' => 0, 'show_date' => '', 'date_format' => get_option('date_format'), 'child_of' => 0, 'exclude' => '', 'title_li' => __('Pages'), 'echo' => 1, 'authors' => '', 'sort_column' => 'menu_order, post_title', 'link_before' => '', 'link_after' => '', 'walker' => '', 'include' => $include_IDs); $r = wp_parse_args($args, $defaults); extract($r, EXTR_SKIP); $output = ''; $current_page = 0; // sanitize, mostly to keep spaces out $r['exclude'] = preg_replace('/[^0-9,]/', '', $r['exclude']); // Allow plugins to filter an array of excluded pages (but don't put a nullstring into the array) $exclude_array = $r['exclude'] ? explode(',', $r['exclude']) : array(); $r['exclude'] = implode(',', apply_filters('wp_list_pages_excludes', $exclude_array)); // Query pages. $r['hierarchical'] = 0; $pages = get_pages($r); if (!empty($pages)) { if ($r['title_li']) { $output .= '<li class="pagenav">' . $r['title_li'] . '<ul>'; } global $wp_query; if (is_page() || is_attachment() || $wp_query->is_posts_page) { $current_page = $wp_query->get_queried_object_id(); } $output .= walk_page_tree($pages, $r['depth'], $current_page, $r); if ($r['title_li']) { $output .= '</ul></li>'; } } $output = apply_filters('wp_list_pages', $output, $r); if ($include_IDs) { if ($r['echo']) { echo $output; } else { return $output; } } else { return false; } }
public function load() { // you only need this if creating custom posts form the form // Get this post to also load in related gravity form data if (parent::load()) { $config_meta = self::CONFIG_META; $config = get_post_meta($this->_post_id, $config_meta, true); $this->config($config); if (!is_numeric($this->lead_id)) { $this->lead_id = get_post_custom_values('lead_id'); } $lead = \GFAPI::get_entry($this->lead_id); if (is_wp_error($lead)) { return false; } $this->load_form_data($lead, $lead['form_id']); } }
function get_post_thumbnail() { if (has_post_thumbnail()) { // 显示特色图像 the_post_thumbnail(); } else { if ($values = get_post_custom_values("picture")) { ?> <a href="<?php the_permalink(); ?> " title="<?php the_title(); ?> "><img class="thumb" src="<?php $values = get_post_custom_values("picture"); echo $values[0]; ?> " alt="<?php the_title(); ?> " /></a> <?php } } /* else { // 设置特色图像 $attachments = get_posts(array( 'post_type' => 'attachment', 'post_mime_type'=>'image', 'posts_per_page' => 0, 'post_parent' => $post->ID, 'order'=>'ASC' )); if ($attachments) { foreach ($attachments as $attachment) { set_post_thumbnail($post->ID, $attachment->ID); break; } // 显示特色图像 } } */ }