function testManuallyAddedFields() { $post_id = 11; // test single/first values $this->assertEquals("Text entered in the text field", simple_fields_value("field_text", $post_id)); $this->assertEquals("Text entered in the textarea", simple_fields_value("field_textarea", $post_id)); $this->assertEquals("<p>Text entered in the TinyMCE-editor.</p>\n", simple_fields_value("field_textarea_html", $post_id)); $this->assertEquals("1", simple_fields_value("field_checkbox", $post_id)); $this->assertEquals("radiobutton_num_4", simple_fields_value("field_radiobuttons", $post_id)); $this->assertEquals("dropdown_num_3", simple_fields_value("field_dropdown", $post_id)); $this->assertEquals(14, simple_fields_value("field_file", $post_id)); $this->assertEquals(11, simple_fields_value("field_post", $post_id)); $this->assertEquals("post_tag", simple_fields_value("field_taxonomy", $post_id)); $this->assertEquals(array(0 => 1), simple_fields_value("field_taxonomy_term", $post_id)); $this->assertEquals("FF3C26", simple_fields_value("field_color", $post_id)); $this->assertEquals("12/10/2012", simple_fields_value("field_date", $post_id)); $this->assertEquals(1, simple_fields_value("field_user", $post_id)); // test repeatable/all values $val = array(0 => "Text entered in the text field", 1 => "text in textfield 2<span>yes it is</span>"); $this->assertEquals($val, simple_fields_values("field_text", $post_id)); $val = array(0 => "Text entered in the textarea", 1 => "Textera with more funky text in it.\r\n\r\n<h2>Headline</h2>\r\n<ul>\r\n\t<li>Item 1</li>\r\n\t<li>Item 2</li>\r\n</ul>\r\n"); $get_vals = simple_fields_values("field_textarea", $post_id); $this->assertEquals($val, $get_vals); $val = array(0 => "<p>Text entered in the TinyMCE-editor.</p>\n", 1 => "<p>Tiny editors are great!</p>\n<p>You can style the content and insert images and stuff. Groovy! Funky!</p>\n<h2>A list</h2>\n<ul>\n<li>List item 1</li>\n<li>List item 2</li>\n</ul>\n<h2>And images can be inserted</h2>\n<p><a href=\"http://unit-test.simple-fields.com/wordpress/wp-content/uploads/2012/10/product-cat-2.jpeg\"><img class=\"alignnone wp-image-14\" title=\"product-cat-2\" src=\"http://unit-test.simple-fields.com/wordpress/wp-content/uploads/2012/10/product-cat-2.jpeg\" alt=\"\" width=\"368\" height=\"277\" /></a></p>\n"); $get_vals = simple_fields_values("field_textarea_html", $post_id); $this->assertEquals($val[1], $get_vals[1]); $val = array(0 => 1, 1 => ""); $this->assertEquals($val, simple_fields_values("field_checkbox", $post_id)); $val = array(0 => "radiobutton_num_4", 1 => "radiobutton_num_2"); $this->assertEquals($val, simple_fields_values("field_radiobuttons", $post_id)); $val = array(0 => "dropdown_num_3", 1 => "dropdown_num_2"); $this->assertEquals($val, simple_fields_values("field_dropdown", $post_id)); $val = array(0 => 14, 1 => 17); $this->assertEquals($val, simple_fields_values("field_file", $post_id)); $val = array(0 => 11, 1 => 5); $this->assertEquals($val, simple_fields_values("field_post", $post_id)); $val = array(0 => "post_tag", 1 => "category"); $this->assertEquals($val, simple_fields_values("field_taxonomy", $post_id)); $val = array(0 => array(0 => 1), 1 => ""); $this->assertEquals($val, simple_fields_values("field_taxonomy_term", $post_id)); $val = array(0 => "FF3C26", 1 => "8B33FF"); $this->assertEquals($val, simple_fields_values("field_color", $post_id)); $val = array(0 => "12/10/2012", 1 => "15/10/2012"); $this->assertEquals($val, simple_fields_values("field_date", $post_id)); $val = array(0 => "1", 1 => "1"); $this->assertEquals($val, simple_fields_values("field_user", $post_id)); }
function get_posts_by_simple_fields_value($args, $postType = 'any') { $rows = get_posts(array('post_type' => $postType, 'numberposts' => -1)); $return = array(); foreach ($rows as $row) { $valueGroups = simple_fields_values($args['key'], $row->ID); if ($valueGroups) { foreach ($valueGroups as $values) { if ($values) { foreach ($values as $value) { if ($value == $args['value']) { $return[] = $row; } } } } } } return count($return) ? $return : false; }
if (function_exists('synved_social_share_markup')) { echo synved_social_share_markup(); } ?> </div> </div> </div> </div> </div> <?php // Author bio. get_template_part('author-bio'); ?> <!-- Check there are product link to this article--> <?php $repeatable_field_values = simple_fields_values("product_name,product_price,product_image,product_link"); if ($repeatable_field_values != NULL) { ?> <div class="section-small pt0"> <h2 class="look-title">Get the look</h2> <div class="section-tiny"> <ul class="row products"> <?php // get each product from array foreach ($repeatable_field_values as $values) { ?> <!-- Display product(s) --> <li> <a href="<?php echo $values["product_link"]; ?>
/** * Outputs the names of the post connectors attached to the post you view + outputs the values */ function simple_fields_content_debug_output($the_content) { // we only want to appen the debug code when being used from get_the_content or the_content // but for example get_the_excerpt is also using filter the_content which leads to problems // so check that we are somewhere inside the right functions $is_inside_righ_function = FALSE; $arr_trace = debug_backtrace(); $arr_trace_count = count($arr_trace); for ($i = 0; $i < $arr_trace_count; $i++) { if (isset($arr_trace[$i]["function"]) && in_array($arr_trace[$i]["function"], array("the_content", "get_the_content"))) { $is_inside_righ_function = TRUE; break; } } if (!$is_inside_righ_function) { // Don't do the debug, since we're not in the_content return $the_content; } $output = ""; $output_all = ""; $field_count = 0; $post_connector_with_values = simple_fields_get_all_fields_and_values_for_post(get_the_ID(), "include_deleted=0"); if ($post_connector_with_values) { foreach ($post_connector_with_values["field_groups"] as $one_field_group) { if ($one_field_group["deleted"]) { continue; } $output_all .= "<div style='font-weight:bold;margin:1em 0 0 0;'>"; $str_is_repeatable = $one_field_group["repeatable"] ? __(" (Repeatable)", "simple-fields") : ""; $output_all .= sprintf(__('Fieldgroup %1$s %2$s', "simple-fields"), $one_field_group["name"], $str_is_repeatable); $output_all .= "</div>"; $str_all_group_fields = ""; foreach ($one_field_group["fields"] as $one_field) { if ($one_field["deleted"]) { continue; } $field_count++; $content = ""; $content .= "<ul style='background:#eee;padding:.5em;margin:0;display:block;'>"; $content .= "<li>Field <b>" . $one_field["name"] . "</b>"; $content .= ", type <b>" . $one_field["type"] . "</b>"; if (isset($one_field["slug"])) { $content .= ", slug <b>" . $one_field["slug"] . "</b>"; $str_all_group_fields .= $one_field["slug"] . ","; if ($one_field_group["repeatable"]) { $content .= "<br>Use <code><b>simple_fields_values('" . $one_field["slug"] . "')</b></code> to get:"; ob_start(); sf_d(simple_fields_values($one_field["slug"])); $content .= ob_get_clean(); } else { $content .= "<br>Use <code><b>simple_fields_value('" . $one_field["slug"] . "')</b></code> to get:"; ob_start(); sf_d(simple_fields_value($one_field["slug"])); $content .= ob_get_clean(); } } else { $content .= "<br>No slug for this field found (probably old field that has not been edited and saved)."; } $content .= "</ul>"; $output_all .= $content; } // Show example how to get all fields in one shot // But only show if field has more than one field, otherwise it's kinda not useful if (sizeof($one_field_group["fields"]) > 1) { $str_all_group_fields = preg_replace('!,$!', '', $str_all_group_fields); $output_all .= "<ul style='background:#eee;padding:.5em;margin:0;display:block;'>"; if ($one_field_group["repeatable"]) { $content = "<li>Get all fields at once: use <code><b>simple_fields_values('" . $str_all_group_fields . "')</b></code> to get:"; ob_start(); sf_d(simple_fields_values($str_all_group_fields)); $content .= ob_get_clean(); } else { $content = "<li>Get all fields at once: use <code><b>simple_fields_value('" . $str_all_group_fields . "')</b></code> to get:"; ob_start(); sf_d(simple_fields_value($str_all_group_fields)); $content .= ob_get_clean(); } $output_all .= $content; $output_all .= "</ul>"; } } // for each field group } if ($output_all) { $str_show_fields = __("Show fields.", "simple-fields"); $str_hide_fields = __("Hide fields.", "simple-fields"); ?> <script> window.simple_fields_post_debug_show_hide = window.simple_fields_post_debug_show_hide || function(t) { var $t = jQuery(t); var $div_wrap = $t.closest("div.simple-fields-post-debug-wrap"); var debug_content = $div_wrap.find("div.simple-fields-post-debug-content"); debug_content.toggle(); if (debug_content.is(":visible")) { $t.text("<?php echo $str_hide_fields; ?> "); } else { $t.text("<?php echo $str_show_fields; ?> "); } return false; } </script> <?php $output_all = ' <div class="simple-fields-post-debug-wrap" style="display:block;margin:0;padding:0;"> <p style="margin:0;padding:0;display:block;">This post has ' . $field_count . ' Simple Fields-fields attached. <a href="#" onclick="return simple_fields_post_debug_show_hide(this);">' . $str_show_fields . '</a></p> <div class="simple-fields-post-debug-content" style="display:none;">' . $output_all . '</div> </div> '; } // if a field has the slug caption the output will be [caption] and then it will crash with some shortcodes, so we try to fix that here $output_all = str_replace("[", "[", $output_all); $output_all = str_replace("]", "]", $output_all); return $the_content . $output_all; }
echo get_site_url(); ?> /articulos" class="btn btn-primary">VER TODOS LOS ARTÍCULOS</a> </div> </div> <div class="col-md-3"> <h2>GALERÍA</h2> <div class="galeria"> <?php query_posts(array('category_name' => 'galeria', 'posts_per_page' => 1)); while (have_posts()) { the_post(); $postid = get_the_ID(); $galeria = simple_fields_values("galeria"); $i = 0; foreach ($galeria as $key => $value) { echo '<div class="img-gal"><a href="' . get_site_url() . '/galerias"><img src="' . $galeria[$i]['image_src']['thumbnail']['0'] . '"></a></div>'; $i++; if ($i == 12) { break; } } ?> <?php } // End of the loop. wp_reset_query();
function testManuallyAddedFields() { $this->insertDataForManualAddedFields(); $post_id = self::$post_id_for_manual_tests; // test single/first values $this->assertEquals("Text entered in the text field", simple_fields_value("field_text", $post_id)); $this->assertEquals("Text entered in the textarea", simple_fields_value("field_textarea", $post_id)); $this->assertEquals("<p>Text entered in the TinyMCE-editor.</p>\n", simple_fields_value("field_textarea_html", $post_id)); $this->assertEquals("1", simple_fields_value("field_checkbox", $post_id)); $this->assertEquals("radiobutton_num_4", simple_fields_value("field_radiobuttons", $post_id)); $this->assertEquals("dropdown_num_3", simple_fields_value("field_dropdown", $post_id)); $this->assertEquals(14, simple_fields_value("field_file", $post_id)); $this->assertEquals($post_id, simple_fields_value("field_post", $post_id)); $this->assertEquals("post_tag", simple_fields_value("field_taxonomy", $post_id)); $this->assertEquals(array(0 => 1), simple_fields_value("field_taxonomy_term", $post_id)); $this->assertEquals("FF3C26", simple_fields_value("field_color", $post_id)); $this->assertEquals("12/10/2012", simple_fields_value("field_date", $post_id)); $this->assertEquals(1, simple_fields_value("field_user", $post_id)); // test that wp_post object can be passed $post_dapost = get_post($post_id); $this->assertEquals("Text entered in the text field", simple_fields_value("field_text", $post_dapost)); // test repeatable/all values #var_dump( simple_fields_values("field_text") ); #exit; #print_r($allvals); $val = array(0 => "Text entered in the text field", 1 => "text in textfield 2<span>yes it is</span>"); $this->assertEquals($val, simple_fields_values("field_text", $post_id)); $val = array(0 => "Text entered in the textarea", 1 => "Textera with more funky text in it.\r\n\r\n<h2>Headline</h2>\r\n<ul>\r\n\t<li>Item 1</li>\r\n\t<li>Item 2</li>\r\n</ul>\r\n"); $get_vals = simple_fields_values("field_textarea", $post_id); $this->assertEquals($val, $get_vals); $val = array(0 => "<p>Text entered in the TinyMCE-editor.</p>\n", 1 => "<p>Tiny editors are great!</p>\n<p>You can style the content and insert images and stuff. Groovy! Funky!</p>\n<h2>A list</h2>\n<ul>\n<li>List item 1</li>\n<li>List item 2</li>\n</ul>\n<h2>And images can be inserted</h2>\n<p><a href=\"http://unit-test.simple-fields.com/wordpress/wp-content/uploads/2012/10/product-cat-2.jpeg\"><img class=\"alignnone wp-image-14\" title=\"product-cat-2\" src=\"http://unit-test.simple-fields.com/wordpress/wp-content/uploads/2012/10/product-cat-2.jpeg\" alt=\"\" width=\"368\" height=\"277\" /></a></p>\n"); $get_vals = simple_fields_values("field_textarea_html", $post_id); $this->assertEquals($val[1], $get_vals[1]); $val = array(0 => 1, 1 => ""); $this->assertEquals($val, simple_fields_values("field_checkbox", $post_id)); $val = array(0 => "radiobutton_num_4", 1 => "radiobutton_num_2"); $this->assertEquals($val, simple_fields_values("field_radiobuttons", $post_id)); $val = array(0 => "dropdown_num_3", 1 => "dropdown_num_2"); $this->assertEquals($val, simple_fields_values("field_dropdown", $post_id)); $val = array(0 => 14, 1 => 17); $this->assertEquals($val, simple_fields_values("field_file", $post_id)); $val = array(0 => $post_id, 1 => 5); $this->assertEquals($val, simple_fields_values("field_post", $post_id)); $val = array(0 => "post_tag", 1 => "category"); $this->assertEquals($val, simple_fields_values("field_taxonomy", $post_id)); $val = array(0 => array(0 => 1), 1 => ""); $this->assertEquals($val, simple_fields_values("field_taxonomy_term", $post_id)); $val = array(0 => "FF3C26", 1 => "8B33FF"); $this->assertEquals($val, simple_fields_values("field_color", $post_id)); $val = array(0 => "12/10/2012", 1 => "15/10/2012"); $this->assertEquals($val, simple_fields_values("field_date", $post_id)); $val = array(0 => "1", 1 => "1"); $this->assertEquals($val, simple_fields_values("field_user", $post_id)); // date & time picker 2 $val = array(0 => array("type" => "datetime", "date_unixtime" => "1359624600", "ISO_8601" => "2013-01-31 09:30", "RFC_2822" => "Thu, 31 Jan 2013 09:30:00 +0000", "Y-m-d" => "2013-01-31", "Y-m-d H:i" => "2013-01-31 09:30", "date_format" => "January 31, 2013", "date_time_format" => "January 31, 2013 9:30 am"), 1 => array("type" => "datetime", "date_unixtime" => "1355162400", "ISO_8601" => "2012-12-10 18:00", "RFC_2822" => "Mon, 10 Dec 2012 18:00:00 +0000", "Y-m-d" => "2012-12-10", "Y-m-d H:i" => "2012-12-10 18:00", "date_format" => "December 10, 2012", "date_time_format" => "December 10, 2012 6:00 pm")); $this->assertEquals($val, simple_fields_values("field_date_picker_2", $post_id)); }
/** * Returns all the values in a field group * It's a shortcut to running simple_fields_value(slugs) with all slugs already entered * Depending if the field group is repeatable or not, simple_field_value or simple_fields_values will be used * * @param mixed $field_group_id_or_slug * @return mixed, but probably array, depending on how many field the group has (just one field, and not repeatable = no array for you!) */ function simple_fields_fieldgroup($field_group_id_or_slug, $post_id = NULL, $options = array()) { if (!is_numeric($post_id)) { global $post; $post_id = $post->ID; } global $sf; $cache_key = "simple_fields_" . $sf->ns_key . "_fieldgroup_" . $field_group_id_or_slug . "_" . $post_id . "_" . md5(json_encode($options)); $values = wp_cache_get($cache_key, 'simple_fields'); if (FALSE === $values) { $field_group = $sf->get_field_group_by_slug($field_group_id_or_slug); $arr_fields = array(); foreach ($field_group["fields"] as $one_field) { if ($one_field["deleted"]) { continue; } // add field group to each field slug $arr_fields[] = trim($one_field["field_group"]["slug"]) . "/" . trim($one_field["slug"]); } $str_field_slugs = join(",", $arr_fields); if ($field_group["repeatable"]) { $values = simple_fields_values($str_field_slugs, $post_id); } else { $values = simple_fields_value($str_field_slugs, $post_id); } wp_cache_set($cache_key, $values, 'simple_fields'); } $values = apply_filters("simple_fields_fieldgroup", $values, $field_group_id_or_slug, $post_id, $options); return $values; }