WordPress.org. The field wordpress


get_sub_field() - Школа WordPress

26 Декабрь 2014 ДимаС

get_sub_field() — ещё одна полезная функция плагина Advanced custom fields, которая используется с повторяющимися полями(repeater field) и flexible content field (лицензионный ключ не требуется), чтобы получить знаечение вложеных полей. Когда функция используется в цикле, она возвращает значения вложеных полей(см. примеры ниже). плагина Advanced custom fields.

Параметры:

1 <?php get_sub_field($sub_field_name); ?>

Пример использования:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 <?php   /* * Цикл для повторяющихся полей "Repeater field" */   if( get_field('repeater') ) { while( has_sub_field('repeater') ) { $variable = get_sub_field('sub_field');   // Делаем что-то с вложенным полем ... } }   /* * Цикл для Flexible Content field (гибкие поля) */   if( get_field('flexible_content') ) { while( has_sub_field("flexible_content") ) { if( get_row_layout() == "paragraph" ) // Размещение: paragraph { $variable = get_sub_field('sub_field');   // Делаем что-то с вложенным полем ... } elseif( get_row_layout() == "file" ) // Размещение: File { $variable = get_sub_field('sub_field');   // Делаем что-то с вложенным полем ... } } }   /* * Циклическое применение вложенных полей Repeater */   if( get_field('parent_repeater') ): ?> <?php while( has_sub_field('parent_repeater') ): ?>   <div> <?php if( get_sub_field('child_repeater') ): ?> <ul> <?php while( has_sub_field('child_repeater') ): ?> <li> <?php   $variable = get_sub_field('sub_field');   // Делаем что-то с вложенным полем ...   ?> </li> <?php endwhile; ?> </ul> <?php endif; ?> </div>   <?php endwhile; ?> <?php endif;   /* * Циклическое применение вложенных полей Repeater (От другого $post ID) */   if( get_field('parent_repeater', 123) ): ?> <?php while( has_sub_field('parent_repeater', 123) ): ?>   <div> <?php   /* * Внимание: Вам не нужно указывать $post_id для вспомогательных функций поля. */   if( get_sub_field('child_repeater') ): ?> <ul> <?php while( has_sub_field('child_repeater') ): ?> <li> <?php   $variable = get_sub_field('sub_field');   // Делаем что-то с вложенным полем ...   ?> </li> <?php endwhile; ?> </ul> <?php endif; ?> </div>   <?php endwhile; ?> <?php endif;   ?>

Читайте также

www.school-wp.net

WP Custom Fields Search | WordPress.org

Описание

With this you can give your readers the ability to search and filter your posts / catalogue to quickly find the information they need. Any custom fields you have added to your posts can be made searchable as well as the core post fields like title, author, categories etc. Configurable input widgets allow you to customise the form further to build exactly the search you need for your site.

You can configure a number of inputs of different types, to search different fields of your posts in different ways. These will then be presented to your users as a simple form interface allowing them to find the content they need.

Add a sidebar widget
  1. Navigate to the widgets page in your wordpress admin area ( Appearance > Widgets )
  2. In the available widgets list you should see «WPCFS Custom Search Form», drag this into the appropriate sidebar.
  3. Add at least one field (see ‘Configuring your form’ below)
  4. click save on the new widget.
  5. Navigate to the front-end of your site

You should now see a very basic search form in that sidebar. You can expand on this using the instructions below under configuring your form

Include a preset
  1. Navigate the WP Custom Fields Search section in the menu
  2. Click the «New Preset» button
  3. Add at least one field (see ‘Configuring your form’ below)
  4. Either copy the shortcode text into a post / page
  5. Or copy the php code into your template
  6. Navigate to the front-end of your site

You should now see a very basic search form in that sidebar. You can expand on this using the instructions below under configuring your form

Configuring your form

** Adding Fields **

Each form consists of a list of fields.

Click the «Add Field» button to add a new field to the list. You will be prompted to select a number of options which will control the appearance and behaviour of your new field. The different settings are described below, but a basic search form could be built from a single field with the following options:

Once you have configured your field close the popup with the X in the top-right corner.

You can add as many fields as you want, and re-order the fields by dragging them up and down the list. You can delete them by clicking the little X icon in the list, and you can reconfigure them by clicking the edit / cog icon in the list.

** Global Settings **

You can name each search form using the text input at the top of the edit form. This name can be displayed to your site visitors (if you click the cog icon to it’s right and tick the option «Show Title?») or it can be helpful if you have a number of forms and need to keep track of which is which.

Input Types / How would you like this field to appear?

The input type controls the form that the user sees when they visit your site to perform a search and how they provide you with a search term. The search term may be something they’ve typed or it might be a selection they’ve made from options you provide.

** Text Input **

A simple text field which allows your visitor to type a free text search query.

This can be powerful when paired with the «Contains Text» comparison as it will match any posts where the configured field contains the visitor’s search term.

By default text inputs treat their input as a single string so if a user types multiple words, they will need to appear in exactly that order. This behaviour can be changed in the input settings options. Click the cog next to the input type selector and you will see the text input settings popup. Choose «Split Words?» to search for each word separately. So e.g. a search for «Big Jumper» might match a post with the text «Big Red Jumper» or «Jumper and Big Socks». The ‘Matches If’ option controls if the resulting posts must contain all the search words, or just any one of them.

** Drop Down **

This creates a html select element or drop-down menu. This is useful where the user must select from a known list of se

ru.wordpress.org

CFS Custom Category Fields | WordPress.org

CFS Category Fields is a Custom Field Suite addon that provides meta data or custom fields for categories and custom taxonomies. Key features are as follows:

  1. Upload cfs-taxonomy.zip to the /wp-content/plugins/ directory
  2. Activate the plugin through the ‘Plugins’ menu in WordPress
  3. Install and activate Custom Field Suite if not already installed
  4. On the Field Group editor you will see a box to apply the Field Group to a Category or Taxonomy
  5. Update the Field Group and the fields will be editable on the WordPress Category Editor
How do I retrieve custom fields for display on a category page?

Use the function get_category_meta(‘field_name’), or alternatively, call CfsTaxonomy::get(‘field_name’) directly, in your php.

How do I retrieve custom category fields anywhere?

Use the function get_category_meta() and pass it the term object as the second parameter, eg: get_category_meta(false, get_term_by(‘slug’, ‘good-stuff’, ‘category’)). This will return all field data from the category Good Stuff.

How do I retrieve the cfs front-end form?

Use the function get_category_form(). If used on a category or archive page it takes no parameters. It can be used anywhere by passing the term object as the first parameter.

«CFS Custom Category Fields» — проект с открытым исходным кодом. В развитие плагина внесли свой вклад следующие участники:

Участники
1.3.1
1.3
1.2.1
1.2
1.1
1.0.1

ru.wordpress.org


Смотрите также

Prostoy-Site | Все права защищены © 2018 | Карта сайта