The Dokani theme comes with a section on the front page with NEW vendors,
I am unable to find the function, but i´d like to modify it to give me a random vendor from the id, maybe?
<?php
$new_sellers = dokan()->vendor->all( array( 'order' => 'DESC', 'number' => 8 ) );
if ( $new_sellers ) { ?>
<input type="radio" name="tabs" id="latest-store">
<label for="latest-store"><?php esc_html_e( 'New', 'dokani' ); ?></label>
<div class="tab">
<?php
$image_size = 'single-vendor-thumb';
$template_args = array(
'sellers' => $new_sellers,
'per_row' => 4,
'image_size' => $image_size,
);
dokan_get_template_part( 'new-store-lists-loop', false, $template_args );
?>
</div>
<?php } ?>
I was thinking in modifying this:
$new_sellers = dokan()->vendor->all( array( 'order' => 'DESC', 'number' => 8 ) );
But I don´t know if this will be enough :(
Related
I made a custom taxonomy for the post post type. I want to use this taxonomy for filtering. I am running the below code in "category.php" page and I am able to do the filtering function.
Screenshot:
For example, the woocommerce attributes filter shows the filters related to the products in your category.
I'm trying to do this in my category.php page. Now, when a category is entered, all filters are listed. is there a way to list only the filters included in that category's posts?
<div class="row">
<?php $args = array(
'taxonomy' => 'filter',
'parent' => 0,
'orderby' => 'name',
'order' => 'ASC',
'hierarchical' => 1,
'hide_empty' => true,
'pad_counts' =>0,
);
$categories = get_categories( $args );
foreach ( $categories as $category ){ ?>
<div class='col'>
<label><?php echo "$category->name"; ?></label>
<ul class='filter'>
<?php $sub_args = array(
'taxonomy' => 'filter',
'parent' => $category->term_id,
'orderby' => 'name',
'order' => 'ASC',
'hierarchical' => 1,
'hide_empty' => true,
'pad_counts' => 0,
);
$sub_categories = get_categories( $sub_args );
foreach ( $sub_categories as $sub_category ){ ?>
<li>
<label>
<input
type="checkbox"
name="filter[]"
value="<?php echo $sub_category->slug; ?>"
<?php checked( (isset($_GET['filter']) && in_array($sub_category->slug, $_GET['filter']))) ?>
/>
<?php echo $sub_category->name; ?>
</label>
<?php
echo "</li>";
}
echo "</ul>";
echo "</li>";
echo "</div>";
}
?>
</div>
<button type="submit">Apply</button>
</form>
If I set post-status to 'publish' (as shown below) this form creates the post, but my acf fields for this post type (some should be auto-populated) aren't added to the database
If I set post-status to 'draft' this form creates the draft - if I edit and save that draft all is good
Any ideas?
Thanks, Richard
<?php acf_form_head(); ?>
<?php get_header(); ?>
<div id="primary" class="rs-add-forms">
<div id="content" class="site-content" role="main">
<?php while ( have_posts() ) : the_post(); ?>
<?php acf_form(array(
'post_id' => 'new_post',
'post_title' => true,
'new_post' => array(
'post_type' => 'people',
'post_status' => 'publish'
),
'fields' => array('field_5ed5c2215be79',),
'submit_value' => 'Create Person',
'html_submit_button' => '<input type="submit" class="rs-add-button" value="%s" />',
'updated_message' => false
)); ?>
<?php endwhile; ?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_footer(); ?>
Since acf_form calls acf_add_local_field on the value of the fields key in the options array, you should try structuring your data like the function parses defaults for, internally.
// Apply default properties needed for import.
$field = wp_parse_args($field, array(
'key' => '',
'name' => '',
'type' => '',
'parent' => '',
));
Therefore, you might modify to
'fields' => array(
array(
'key' => 'field_5ed5c2215be79',
'name' => 'Form Field Title',
'type' => 'registered_acf_fieldtype',
'parent' => '[probably optional]'
)
),
In the related products section, I would like to filter out certain products. I cannot simply hide these products from the shop as I want to use them in the up-sells section.
In the related.php file, is there any argument I can use to filter out certain products? The products I want to filter, all contain the word "set" in them, and they also have a class "setBadge". Can I use these to somehow filter them out? (I cannot use css for this as if I use display: none they leave an empty space, I want to exclude them from the loop).
$args = apply_filters('woocommerce_related_products_args', array(
'post_type' => 'product',
'ignore_sticky_posts' => 1,
'no_found_rows' => 1,
'posts_per_page' => $posts_per_page,
'orderby' => $orderby,
'post__in' => $related,
'post__not_in' => array($product->id)
) );
I couldn't find a simple way to do this without $wpdb but you can try something like this maybe-
$search_query = 'iPhone air pods';
$break_query = explode(' ', $search_query);
$final_params = [];
/* $break_query = array(
'iphone',
'air',
'pods'
); */
foreach( $break_query as $q ) {
$args = array(
'key' => '_price',
'value' => $q,
'compare' => '<=',
'type' => 'NUMERIC'
);
array_push( $final_params, $q );
}
$params = array(
'posts_per_page' => 100,
'post_type' => array('product', 'product_variation'),
'meta_query' => array(
'relation' => 'OR',
$final_params
)
);
This code haven't been tested but what i did here is that-
I've splitted the main query per word and then I've dynamically created the $params array. The relation is "OR" so if any of these keywords are found, the product will be displayed.
Another option is to use WooCommerce's default search-
<form role="search" method="get" class="woocommerce-product-search" action="<?php echo esc_url( home_url( '/' ) ); ?>">
<label class="screen-reader-text" for="s"><?php _e( 'Search for:', 'woocommerce' ); ?></label>
<input type="search" class="search-field" placeholder="<?php echo esc_attr_x( 'Search Products…', 'placeholder', 'woocommerce' ); ?>" value="<?php echo get_search_query(); ?>" name="s" title="<?php echo esc_attr_x( 'Search for:', 'label', 'woocommerce' ); ?>" />
<input type="submit" value="<?php echo esc_attr_x( 'Search', 'submit button', 'woocommerce' ); ?>" />
<input type="hidden" name="post_type" value="product" />
</form>
How to select multiple category with wp_dropdown_categories , it only allows single category to select.
<p class="<?php if (get_option('jr_submit_cat_required')!=='yes') : echo 'optional'; endif; ?>" <label for="job_cat"><?php _e('Job Category', 'appthemes'); ?> <?php if (get_option('jr_submit_cat_required')=='yes') : ?><span title="required">*</span><?php endif; ?></label> <?php
$sel = 0;
if (isset($posted['job_term_cat']) && $posted['job_term_cat']>0) $sel = $posted['job_term_cat'];
global $featured_job_cat_id;
$args = array(
'orderby' => 'name',
'exclude' => $featured_job_cat_id,
'order' => 'ASC',
'name' => 'job_term_cat',
'hierarchical' => 0,
'echo' => 0,
'class' => 'chzn-select',
'selected' => $sel,
'taxonomy' => 'job_cat',
'hide_empty' => false
);
$dropdown = wp_dropdown_categories( $args);
$dropdown = str_replace( 'class=\'job_cat\' \'chzn-select\'>', 'class=\'job_cat\' \'chzn-select\'><option value="">'.__('Select a category…', 'appthemes').'</option>',$dropdown);
echo $dropdown;
?></p>
I was to use it as a multiple select. i have try every way i can imagine entering it in the str_replace, with no luck. I know this cant possibly be as difficult as im making it, id really appreciate any help :-)
Replace str_replace with preg_replace.
$dropdown = preg_replace( 'class=\'job_cat\' \'chzn-select\'>', 'class=\'job_cat\' \'chzn-select\'><option value="">'.__('Select a category…', 'appthemes').'</option>',$dropdown);
I've an unique situation where I need to display same comments for 3 different posts. This 3 different posts are obviously linked together in DB. So what I need to do is to force use of 1 post ID for all languages to submit comment and retrieve it... instead of using 3 diff IDs I need to use 1 and stick to it.
I've $current_post_duplicate_id which is 9 for all 3 translated posts.
If I submit comment on original post which is originally post_ID 9 all works fine, I see comment and it gets submited. But when I switch to translated version nothing is displayed, but I'm forcing get_comments to use id 9 for displaying and submiting comments through $current_post_duplicate_id, so what is happening? why is not this working??
I cannot figure out what is happening, I figured some guru here could give me a hint.
<?php
//Uniting comments in all languages by setting default language for comments en in this case
$current_post_duplicate_id = icl_object_id (get_queried_object_id(), 'tribe_events', false, 'en');
?>
<div id="eventattend">
<?php if ('open' == $post->comment_status) : ?>
<span><?php _e('Are you intersted?'); ?></span>
<?php if ( $user_ID ) : ?>
<?php
$usercomment = get_comments( array( 'user_id' => $current_user->ID, 'post_id' => $current_post_duplicate_id ) );
if ( 1 <= count( $usercomment ) ) {
?>
<form method="post" action="">
<a class="eventno" href="javascript:;" onclick="parentNode.submit();"><?php _e('No'); ?></a>
<input type="hidden" name="delmycom" value="1" />
<?php
//
$delete_my_event_interest = $_POST['delmycom'];
//
if ( isset ($delete_my_event_interest) ) {
$current_user_comment = get_comments( array(
'post_id' => $current_post_duplicate_id,
'user_id' => get_current_user_id(),
'number' => 1,
'status' => 'approve',
'type' => 'comment'
) );
wp_delete_comment( $current_user_comment[0]->comment_ID );
}
//
?>
</form>
<?php } else { ?>
<form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post">
<?php comment_id_fields(); ?>
<?php do_action('comment_form', $current_post_duplicate_id); ?>
<input type="hidden" name="comment" value="I'm attending this Event!" />
<a class="eventyes" href="javascript:;" onclick="parentNode.submit();"><?php _e('Yes'); ?></a>
</form>
<?php } ?>
<?php else : ?>
<a class="eventyes loginosx" href="#"><?php _e('Yes'); ?></a>
<?php _e('*You need to be loged in to say YES.'); ?>
<?php endif; ?>
<?php endif; // if you delete this the sky will fall on your head ?>
<div class="clearfloat"></div><!-- Very Important -->
<!-- End #eventattend --></div>
<!-- End #eventsingle --></div>
<ul class="sidebarlists" id="interestedlist">
<li>
<h2><?php _e('Who\'s interested so far?'); ?> (<?php comments_number( '0', '1', '%' ); ?>)</h2>
<ul>
<?php
$recent_comments = get_comments( array(
'post_id' => $current_post_duplicate_id,
'number' => 25,
'status' => 'approve',
'type' => 'comment',
'order' => 'ASC'
) );
foreach ($recent_comments as $comment) {
?>
<li id="attendee-<?php echo $comment->comment_ID; ?>">
<?php echo get_avatar( $comment->comment_author_email, $size = '50', $alt = $comment->comment_author.' is attending this event' ); ?>
<span><?php echo $comment->comment_author; ?></span>
</li>
<?php
}
?>
</ul>
</li>
<!-- End #sidebarlists --></ul>
use this
<?php $comments = get_comments(array('post_id' => 1)); ?>
You can also pass the following parameters
<?php $defaults = array(
'author_email' => '',
'ID' => '',
'karma' => '',
'number' => '',
'offset' => '',
'orderby' => '',
'order' => 'DESC',
'parent' => '',
'post_id' => 0,
'post_author' => '',
'post_name' => '',
'post_parent' => '',
'post_status' => '',
'post_type' => '',
'status' => '',
'type' => '',
'user_id' => '',
'search' => '',
'count' => false,
'meta_key' => '',
'meta_value' => '',
'meta_query' => '',
); ?>