/
data.php
117 lines (96 loc) · 3.16 KB
/
data.php
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
/**
* Data
*
* @package Understrap
*/
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;
add_action( 'init', 'create_theme_taxonomies', 0 );
function create_theme_taxonomies()
{
// Add new taxonomy, NOT hierarchical (like tags)
$labels = array(
'name' => _x( 'Themes', 'taxonomy general name' ),
'singular_name' => _x( 'theme', 'taxonomy singular name' ),
'search_items' => __( 'Search Themes' ),
'popular_items' => __( 'Popular Themes' ),
'all_items' => __( 'All Themes' ),
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => __( 'Edit Themes' ),
'update_item' => __( 'Update theme' ),
'add_new_item' => __( 'Add New theme' ),
'new_item_name' => __( 'New theme' ),
'add_or_remove_items' => __( 'Add or remove Themes' ),
'choose_from_most_used' => __( 'Choose from the most used Themes' ),
'menu_name' => __( 'Theme' ),
);
//registers taxonomy specific post types - default is just post
register_taxonomy('themes', array('post'), array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'update_count_callback' => '_update_post_term_count',
'query_var' => true,
'rewrite' => array( 'slug' => 'theme' ),
'show_in_rest' => true,
'rest_base' => 'theme',
'rest_controller_class' => 'WP_REST_Terms_Controller',
'show_in_nav_menus' => true,
));
}
//from https://nustart.solutions/code-snippet/gravity-forms-populate-dropdown-taxonmy/
//Adds a filter to form id 1. Replace 3 with your actual form id
add_filter('gform_pre_render_1', 'glocal_populate_theme_dropdown');
function glocal_populate_theme_dropdown($form){
$terms = get_terms( array(
'taxonomy' => 'themes',
'hide_empty' => false,
'orderby' =>'title',
'order' =>'ASC',
) );
//Creating drop down item array.
$items = array();
//Adding initial blank value.
$items[] = array("text" => "", "value" => "");
//Adding post titles to the items array
foreach($terms as $term)
$items[] = array(
"value" => $term->name,
"text" => $term->name
);
//Adding items to field id 11
foreach($form["fields"] as &$field)
if($field["id"] == 11){
$field["type"] = "select";
$field["choices"] = $items;
}
return $form;
}
add_filter('gform_pre_render_1', 'glocal_populate_category_dropdown');
function glocal_populate_category_dropdown($form){
$terms = get_terms( array(
'taxonomy' => 'category',
'hide_empty' => false,
'orderby' =>'title',
'order' =>'ASC',
) );
//Creating drop down item array.
$items = array();
//Adding initial blank value.
$items[] = array("text" => "", "value" => "");
//Adding post titles to the items array
foreach($terms as $term)
$items[] = array(
"value" => $term->name,
"text" => $term->name
);
//Adding items to field id 11
foreach($form["fields"] as &$field)
if($field["id"] == 12){
$field["type"] = "select";
$field["choices"] = $items;
}
return $form;
}