I'm trying to find how can I display the list of imported properties. The problem is the metadata, after import the properties are not visible on the frontend and I need to update every item manually. How can I update metadata editing a following code:
<?php
$args = array(
'posts_per_page' => $custom_property_items_amount,
'post_type' => 'property',
'orderby' => array(
'menu_order'=>'ASC',
'date' =>'DESC',
),
'offset' => ( max( 1, get_query_var( 'paged' ) ) - 1 ) * $custom_property_items_amount,
'ignore_sticky_posts' => 1,
'post_status' => array('publish','pending','draft','future','private'),
);
$data = new WP_Query( $args );
?>
<div class="<?php echo join( ' ', $wrapper_classes ) ?>">
<?php if ( $data->have_posts() ) :
while ( $data->have_posts() ): $data->the_post(); ?>
<?php ere_get_template( 'content-property.php', array(
'custom_property_image_size' => $custom_property_image_size,
'property_item_class' => $property_item_class
)); ?>
<?php endwhile;
else: ?>
<div class="item-not-found"><?php esc_html_e( 'Not found', 'essential-real-estate' ); ?></div>
<?php endif; ?>
<div class="clearfix"></div>
<?php
$max_num_pages = $data->max_num_pages;
ere_get_template( 'global/pagination.php', array( 'max_num_pages' => $max_num_pages ) );
wp_reset_postdata(); ?>
</div>
Solved! The problem was in this part of the code:
if (!empty($features)) {
foreach($features as $feature){
$tax_query[] = array(
'taxonomy' => 'property-feature',
'field' => 'slug',
'terms' => $feature
);
$parameters.=sprintf( __('Feature: <strong>%s</strong>; ', 'essential-real-estate'), $feature);
}
}
$args['meta_query'] = array(
'relation' => 'AND',
$meta_query
);
$tax_count = count($tax_query);
if ($tax_count > 0) {
$args['tax_query'] = array(
'relation' => 'AND',
$tax_query
);
}
By deleting this all the items were displayed.
Related
I have a group of posts that can select a custom field 'Partner Content'. These posts then select their post author. The post author is a custom post type that has a relationship field that selects the 'Partner Company' associated with the post author.
I am now trying to set up a single-partner_company.php template that displays all posts associated with the specific company. My meta query looks like this:
<?php
$current_company = $post;
$comp_id = $current_company->ID;
$comp_name = $current_company->post_title;
?>
<?php
$current_company = $post;
$comp_id = $current_company->ID;
$comp_name = $current_company->post_title;
?>
<?php
$args = array(
'numberposts' => -1,
'fields' => 'ids',
'post_type' => 'partner_authors',
'meta_query' => array(
'key' => 'author_company',
'value' => $current_company
)
);
$authors = get_posts( $args );
$post_args = array(
'fields' => 'ids',
'numberposts' => 3,
'post_type' => 'post',
'meta_query' => array(
'key' => 'post_author',
'value' => $authors
)
);
$partner_posts = get_posts( $post_args );
$count = 0;
?>
neither array is working for me. what am I doing wrong?
Am trying to display users list as mail.Here it is my code,but there is no response
<?php
$data = Users::find()
->select(['user_email as value', 'user_id as id'])
->asArray()
->all();
echo AutoComplete::widget([
'name' => 'user_email',
'id' => 'ddd',
'clientOptions' => [
'source' => $data,
'autoFill'=>true,
'minLength'=>'1',
'select' => new JsExpression("function( event, ui ) {
$('#user_mail_1').val(ui.item.id);
}")],
]);
?>
<?= $form->field($model, 'user_email')->HiddenInput(['id' => 'user_mail_1'])->label(false) ?>
You need to use label for display value of auto complete input value.
So, get user_email as label like as:
<?php
use yii\web\JsExpression;
$data = Users::find()
->select(['user_email as value', 'user_id as id', 'user_email as label'])
->asArray()
->all();
// OR try below query for get data.
$data = (new \yii\db\Query())
->select(["user_email as value", "user_email as label","user_id as id"])
->from('users u')
->all();
echo AutoComplete::widget([
'name' => 'user_email',
'id' => 'ddd',
'clientOptions' => [
'source' => $data,
'autoFill'=>true,
'minLength'=>'1',
'select' => new JsExpression("function( event, ui ) {
$('#".Html::getInputId($model, 'user_email')."').val(ui.item.id); // Html::gtInputId() get dynamic id of input field.
}")],
]);
?>
<?= $form->field($model, 'user_email')->hiddenInput()->label(false) ?>
I defined a custom field, to be able to hide posts from home, like this:
/* Campo adicional que puede ocultar noticia de la home */
function mnd_get_custom_field( $value ) {
global $post;
$custom_field = get_post_meta( $post->ID, $value, true );
if ( !empty( $custom_field ) )
return is_array( $custom_field ) ? stripslashes_deep( $custom_field ) : stripslashes( wp_kses_decode_entities( $custom_field ) );
return false;
}
function mnd_add_custom_meta_box() {
add_meta_box( 'home-page', __( 'Home page', 'mnd' ), 'mnd_meta_box_output', 'post', 'normal', 'high' );
}
add_action( 'add_meta_boxes', 'mnd_add_custom_meta_box' );
function mnd_meta_box_output( $post ) {
wp_nonce_field( 'my_mnd_meta_box_nonce', 'mnd_meta_box_nonce' ); ?>
<p>
<label for="mnd_hide_homepage"><?php _e( 'Hide from homepage', 'mnd' ); ?>:</label>
<input type="checkbox" name="mnd_hide_homepage" id="mnd_hide_homepage" checked="<?php echo mnd_get_custom_field( 'mnd_hide_homepage' ) == 1 ? 'checked' : ''; ?>" value="1" size="50" />
</p>
<?php
}
function mnd_meta_box_save( $post_id ) {
if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
if( !isset( $_POST['mnd_meta_box_nonce'] ) || !wp_verify_nonce( $_POST['mnd_meta_box_nonce'], 'my_mnd_meta_box_nonce' ) ) return;
if( !current_user_can( 'edit_post', get_the_id() ) ) return;
if( isset( $_POST['mnd_hide_homepage'] ) )
update_post_meta( $post_id, 'mnd_hide_homepage', esc_attr( $_POST['mnd_hide_homepage'] ) );
}
add_action( 'save_post', 'mnd_meta_box_save' );
and I'm trying like:
// The Query
$ppp = 12;
$page = $_GET['page'];
$args_count = array(
'post_type' => 'post',
'paged' => false,
'status' => 'publish'
);
$posts_home_count = new WP_Query( $args_count );
$manyPosts = $posts_home_count->found_posts;
$paginas = $manyPosts / $ppp;
wp_reset_postdata();
$meta_params = array(
array(
'key' => 'mnd_hide_homepage',
'value' => 1,
'compare' => '!=',
'type' => 'NUMERIC'
)
);
$args = array(
'post_type' => 'post',
'posts_per_page' => $ppp,
'paged' => $page,
'page' => $page,
'status' => 'publish'/*,
'meta_query' => $meta_params */
);
//print_r ( $args );
$posts_home = new WP_Query( $args );
And it won't return any posts,
But if I change to
'compare' => '=',
Then it returns all the checked posts
Any idea what I'm missing?
There are some problems with Meta Query sometimes and the problem is not always visible. Try the following:
var_dump the WP_Query object and check the SQL manually. Do you see the problem?
Did you try to remove 'type' => 'NUMERIC'?
The “hack” solution (untested):
global $wpdb;
$ids = $wpdb->get_results("
SELECT $wpdb->posts.id FROM $wpdb->posts
WHERE post_status=publish
INNER JOIN $wpdb->post_meta
ON $wpdb->post_meta.post_id = $wpdb->posts.id
AND $wpdb->post_meta.key = 'mnd_hide_homepage'
AND $wpdb->post_meta.value != '1'
");
// put the ids with post__in into the WP_Query arguments
Maybe this is the solution. If not, it may help to find it.
Try this:
array(
'key' => 'mnd_hide_homepage',
'value' => '1',
'compare' => '!=',
'type' => 'NUMERIC'
)
Or
array(
'key' => 'mnd_hide_homepage',
'value' => array('1'),
'compare' => 'NOT IN'
)
I am creating a magento custom admin module and a form. I want update this form but not updating. In Controller, under SaveAction() I print $this->getRequest()->getPost() and get empty array. please help me. Below code for form declination..
protected function _prepareForm() {
$form = new Varien_Data_Form(array(
'id' => 'edit_form1',
'action' => $this->getUrl('*/*/save', array('id' => $this->getRequest()->getParam('id'))),
'method' => 'post',
'enctype' => 'multipart/form-data'
)
);
$form->setUseContainer(true);
$this->setForm($form);
return parent::_prepareForm();
}
And Create a from filed set like
protected function _prepareForm() {
$form = new Varien_Data_Form();
$this->setForm($form);
$fieldset = $form->addFieldset('qbanner_form', array('legend' => Mage::helper('qbanner')->__('Art information')));
$fieldset->addField('name', 'text', array(
'label' => Mage::helper('catalog')->__('Product'),
'required' => false,
'name' => 'name',
));
$fieldset->addField('artist_name', 'text', array(
'label' => Mage::helper('catalog')->__('Artist Name'),
// 'name' => 'artist_name',
'value' => Mage::helper('catalog')->__('Art Name value'),
));
$fieldset->addField('bca_status', 'select', array(
'label' => Mage::helper('catalog')->__('Art status'),
'name' => 'bca_status',
'values' =>$this->_getAttributeOptions('bca_status'),
));
$fieldset->addField('reason', 'editor', array(
'name' => 'reason',
'label' => Mage::helper('catalog')->__('Reason'),
'title' => Mage::helper('catalog')->__('Reason'),
'style' => 'width:440px; height:300px;',
'wysiwyg' => true,
'required' => false,
));
$fieldset->addField('thumbnail', 'text', array(
'label' => Mage::helper('catalog')->__('Art status'),
'name' => 'thumbnail',
//'values' =>$this->_getAttributeOptions('thumbnail'),
//'renderer' => 'Qaz_Qbanner_Block_Adminhtml_Qbanner_Grid_Renderer_Image'
));
if (Mage::getSingleton('adminhtml/session')->getQbannerData()) {
$form->setValues(Mage::getSingleton('adminhtml/session')->getQbannerData());
Mage::getSingleton('adminhtml/session')->setQbannerData(null);
} elseif (Mage::registry('qbanner_data')) {
$form->setValues(Mage::registry('qbanner_data')->getData());
}
return parent::_prepareForm();
}
protected function _getAttributeOptions($attribute_code)
{
$attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', $attribute_code);
$options = array();
foreach( $attribute->getSource()->getAllOptions(true, true) as $option ) {
$options[$option['value']] = $option['label'];
}
return $options;
}
Here my
SaveAction()
public function saveAction() {
echo print_r( $this->getRequest()->getPost());
}
I have tied verious post. Any ideas?
Common error for all. You just need to add form key to your form.
Just add this line below your form declaration.
<input type="hidden" name="form_key" value="<?php echo Mage::getSingleton('core/session')->getFormKey(); ?>" />
Like this
<form action="<?php echo Mage::helper("adminhtml")->getUrl("demo/adminhtml_demo/demo");?>" method="post" id="custom-payment-form" enctype="multipart/form-data">
<input type="hidden" name="form_key" value="<?php echo Mage::getSingleton('core/session')->getFormKey(); ?>" />
Add this. Now you can get parameters by $this->getRequest()->getPost().
you can get variable of post and get method in magento with $this->getRequest()->getParams(); getParams() method But if you want to get exactly some variable data then use getParam('id');
/magento/catalog/product/view/id/406/category/14
$this->getRequest()->getParam('id') // 406
$this->getRequest()->getParams(); //get all get and post variables
I have some trouble making a customized breadcrumb:
I my layout.phtml I have:
$container = new Zend_Navigation();
$this->navigation($container);
$container->addPage(
array(
'label' => 'Dashboard',
'module' => 'default',
'controller' => 'dashboard',
'action' => 'index',
'pages' =>
array(
array(
'label' => 'Create Order',
'module' => 'default',
'controller' => 'createorder',
'action' => 'index'
),
array(
'label' => 'Query',
'module' => 'default',
'controller' => 'query',
'action' => 'index',
'pages' => array(
array(
'label' => 'View Order',
'module' => 'default',
'controller' => 'order',
'action' => 'vieworder'
)
)
),
array(
'label' => 'Administration',
'module' => 'default',
'controller' => 'admin',
'action' => 'index',
'pages' =>
array(
array(
'label' => 'News and Announcements',
'module' => 'default',
'controller' => 'admin',
'action' => 'addnews',
'pages' => array(
array(
'label' => 'Edit News and Announcements',
'module' => 'default',
'controller' => 'admin',
'action' => 'editnews'
)
)
)
)
)
)
)
);
The next line is:
echo $this->navigation()->breadcrumbs()->setPartial(array('BreadCrumb.phtml','default'));
The BreadCrumb.phtml is called well, but I don't know how to make an ul-li menu in my BreadCrumb.phtml. How do I get the navigation I'm actually in?
Thanks in advance for any help. Andrea
To do so, your BreadCrumb.phtml should look like this:
<?php
if (null === $this->container) {
$this->container = $this->breadcrumbs()->getContainer();
}
// find deepest active
if (!$active = $this->breadcrumbs()->findActive($this->container)) {
return '';
}
$active = $active['page'];
// put the deepest active page last in breadcrumbs
if ($this->breadcrumbs()->getLinkLast()) {
$html = ' <li>' . $this->breadcrumbs()->htmlify($active) . '</li>' . PHP_EOL;
} else {
$html = $active->getLabel();
if ($this->breadcrumbs()->getUseTranslator() && $t = $this->breadcrumbs()->getTranslator()) {
$html = $t->translate($html);
}
$html = ' <li>' . $this->escape($html) . '</li>' . PHP_EOL;
}
// walk back to root
while (($parent = $active->getParent()) != null) {
if ($parent instanceof Zend_Navigation_Page) {
// prepend crumb to html
$html = ' <li>' . $this->breadcrumbs()->htmlify($parent) . '</li>' . PHP_EOL . $html;
}
if ($parent === $this->container) {
// at the root of the given container
break;
}
$active = $parent;
}
echo strlen($html) ? $this->breadcrumbs()->getIndent() . '<ul id="breadcrumbs">' . PHP_EOL
. $html . '</ul>' . PHP_EOL : '';
?>
Then you will get something like this:
<ul id="breadcrumbs">
<li>Home</li>
<li>Articles</li>
<li>Shop</li>
<li>Last link</li>
</ul>
Inside the view script, the zend navigation container is retrievable via $this->container. The container is iterable, so you can walk through it with a simple foreach loop (e.g. foreach($this->container as $page)
I've found simple solution for render breadcrumbs wrapped in ul-li menu.
You can place this code in your breadcrumbs.phtml:
<?php $breadcrumbs = $this->navigation()->breadcrumbs()->setMinDepth(0); ?>
<?php $items = array_filter(explode($breadcrumbs->getSeparator(), $breadcrumbs->render())); ?>
<?php if ($items) : ?>
<ul class="breadcrumbs">
<?php foreach ($items as $item) : ?>
<li><?= $item ?></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>