Ask your WordPress questions! Pay money and get answers fast! (more info)

Taxonomy Category for Detail field WordPress

  • REFUNDED

Hello,

I need to do some changes on a theme that I bought.

One of them is I need to organize a field Detail in categories.

Here is my meta_details.php on Admin area

<?php
$meta_boxes = array(
'title' => sprintf( __( 'Details', IT_TEXTDOMAIN ), THEME_NAME ),
'id' => 'it_post_details',
'pages' => array( 'post' ),
'callback' => '',
'context' => 'normal',
'priority' => 'high',
'fields' => array()
);

#populate the details fields array
$details_fields = array();
$details = it_get_setting('review_details');
$details = !empty($details) ? $details : array();
foreach($details as $detail) {
if(isset($detail[0]) && is_object($detail[0])) {
$name = $detail[0]->name;
$meta_name = $detail[0]->meta_name;
if(!empty($name)) {
array_push($details_fields,
array(
'name' => $name,
'id' => $meta_name,
'type' => 'textarea',
'parent' => $parent_name,
'hierarchical' => true,
)
);
}
}
}

#add criteria fields array to meta boxes array
$meta_boxes['fields'] = array_merge($meta_boxes['fields'],$details_fields);

return array(
'load' => true,
'options' => $meta_boxes
);

?>


And my review code



class itDetail{
public $name = null;
public $safe_name = null;
public $meta_name = null;
public $parent_item = null;

function __construct($name, $safe_name = NULL, $meta_name = NULL){
$this->name = $name;

$safe_name = strtolower(str_replace(" ","_",$name));
$meta_name = '_' . $safe_name;

$this->safe_name = $safe_name;
$this->meta_name = $meta_name;
$this->parent_item = $parent_item;
}
}


I am trying to use parent_item that I read on taxonomy. But it is not working.

Anyone can help me?

Answers (3)

2015-06-16

John Cotton answers:

<blockquote>I am trying to use parent_item that I read on taxonomy.</blockquote>

Nowhere in your itDetail class is $parent_item declared, which is why it doesn't work.

Where are you using itDetail? I can't see that used in the other code.


keafao comments:

Hmm, can you help correct my code? I am not a developer, I have few projects in ruby, django and jsf but I could not understand how the model/control is working here.

It detail is used in review.php too

if(!function_exists('it_get_details')) {
#html display of the details fields
function it_get_details($postid, $image, $isreview){
$out = '';
$d = '';
$flag = false;
$details = it_get_setting('review_details');
$details_hide = it_get_setting('review_details_hide');
$affiliate_position = it_get_setting('affiliate_position');
if(empty($details)) $details_hide = true;
$title = it_get_setting('review_details_label');
$title = ( !empty($title) ) ? $title : __('Overview',IT_TEXTDOMAIN);
$item_reviewed = get_post_meta($postid, "_item_reviewed", $single = true);
$item_reviewed = empty($item_reviewed) ? get_the_title() : $item_reviewed;
if($details_hide) return false;
#loop through details and add to string
foreach($details as $detail) {
if(is_array($detail)) {
if(array_key_exists(0, $detail)) {
$name = $detail[0]->name;
if(!empty($name)) {
$meta_name = $detail[0]->meta_name;
$meta = do_shortcode(wpautop(get_post_meta($postid, $meta_name, $single = true)));
if(!empty($meta)) {
$flag = true;
$d .= '<div class="detail-item">';
$d .= '<span class="detail-label meta-label">'.esc_attr($name).'</span>';
$d .= '<div class="detail-content">'.$meta.'</div>';
$d .= '</div>';
}
}
}
}
}

#html output
if($flag) {
$out .= '<div id="overview-anchor" class="clearfix padded-panel">';
$out .= it_ad_action('details_before');
$out .= '<div class="details-box-wrapper" style="background-image:url(' . esc_attr($image) . ');">';
$out .= '<div class="details-box-overlay"></div>';
$out .= '<div class="details-box">';
$out .= '<div class="bordered-label-wrapper"><div class="bordered-label">' . esc_attr($title) . '</div></div>';
$out .= '<div class="details-wrapper">';
if($affiliate_position=='before-overview') {
$out .= '<div class="detail-item">';
$out .= it_get_affiliate_code($postid);
$out .= '</div>';
}
$out .= $d;
if($affiliate_position=='after-overview') {
$out .= '<div class="detail-item">';
$out .= it_get_affiliate_code($postid);
$out .= '</div>';
}
$out .= '</div>';
$out .= '</div>';
$out .= '</div>';
$out .= it_ad_action('details_after');
$out .= '</div>';
}

return $out;
}
}

2015-06-16

MJ answers:

I can see you have a meta box for Posts, which accepts some kind of "review details". This presumably is to allow a user to add these details while they are editing a Post.

I can see your class itDetail which doesn't seem to do too much on its own.

I can see review.php which looks like it shows the "review details" on the front-end, but can't see where it's called.


I'm finding it difficult to understand what you are trying to do. I think it would help if you begin by describing in detail exactly what you want to achieve.


keafao comments:

MJ, yes meta box is where I can create, edit, update and delete Detail Type.

It is a box on Post page.

Class itDetail is where I create, edit, update and delete Detail Name.


I am trying to have Details in Category.

Example:
Car Specs

Category => Motor
Detail Name => Model Motor
Detail Type => Model Number 111111

Category => Tires
Detail Name => Tire Manufacter
Detail Type => Pirelli

I need the detail, so I am trying to have a Parent like WP has on Page and Categories. But for Details.

http://generatewp.com/taxonomy/?clone=car-manufacturer-taxonomy

Best



MJ comments:

I'm going to throw in a plugin for you to consider, because I think it makes handling taxonomies and custom post types very easy, and if you're not a coder it will likely save you a lot of time. It's the WP Types plugin which is free https://wordpress.org/plugins/types/

Is that an option for you?


keafao comments:

Hello MJ,

Did not worked, I would need it to be able to use inside Details.

Best

2015-06-17

Arnav Joy answers:

why you don't use Advance custom fields plugin ?

http://www.advancedcustomfields.com/


keafao comments:

Because the theme has a compare feature that I want to use.

It get the details from products and compare.

Best