• Hello,

    Greetings of the day!
    I am a WordPress developer currently using your Woo-commerce plugin to my new website. On query of default product category listing page I want to add some custom arguments like some taxonomy Id which will display the product listing on the basis of newly constructed taxonomy code.

    Taking an example to clarify the doubt: –

    add_filter(‘pre_get_posts’,’better_editions_archive’);

    function better_editions_archive($query) {

    if ( $query->is_main_query() ) {

    $query->set( ‘post_type’, array( ‘product’ ) );

    $query->set( ‘tax_query’,
    array(
    array(
    ‘taxonomy’ => ‘multi_vendor’,
    ‘field’ => ‘id’,
    ‘terms’ => array( 6, 7, 8 ),

    )
    )
    );

    }

    return $query;
    }

    I used this code in theme’s function.php file but it is not working.

    A help from any expert will be highly appreciated.

    https://www.ads-software.com/plugins/woocommerce/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter sbhagirath

    (@sbhagirath)

    post_type_link show error

    Thread Starter sbhagirath

    (@sbhagirath)

    I have create a custom post type and code is below :

    add_action( ‘init’, ‘register_cpt_top_ten’ );
    function register_cpt_top_ten() {
    $labels = array(
    ‘name’ => _x( ‘Top Ten’, ‘top_ten’ ),
    ‘singular_name’ => _x( ‘Top Ten’, ‘top_ten’ ),
    ‘add_new’ => _x( ‘Add New’, ‘top_ten’ ),
    ‘add_new_item’ => _x( ‘Add New Top Ten’, ‘top_ten’ ),
    ‘edit_item’ => _x( ‘Edit Top Ten’, ‘top_ten’ ),
    ‘new_item’ => _x( ‘New Top Ten’, ‘top_ten’ ),
    ‘view_item’ => _x( ‘View Top Ten’, ‘top_ten’ ),
    ‘search_items’ => _x( ‘Search Top Ten’, ‘top_ten’ ),
    ‘not_found’ => _x( ‘No Top Ten found’, ‘top_ten’ ),
    ‘not_found_in_trash’ => _x( ‘No Top Ten found in Trash’, ‘top_ten’ ),
    ‘parent_item_colon’ => _x( ‘Parent Top Ten:’, ‘top_ten’ ),
    ‘menu_name’ => _x( ‘Top Ten’, ‘top_ten’ ),
    );
    $args = array(
    ‘labels’ => $labels,
    ‘hierarchical’ => false,
    ‘supports’ => array( ‘title’, ‘editor’, ‘excerpt’, ‘author’, ‘thumbnail’, ‘trackbacks’, ‘custom-fields’, ‘comments’, ‘revisions’, ‘page-attributes’ ),
    ‘taxonomies’ => array( ‘product_type’ ),
    ‘public’ => true,
    ‘show_ui’ => true,
    ‘show_in_menu’ => true,
    ‘menu_position’ => 5,
    ‘show_in_nav_menus’ => true,
    ‘publicly_queryable’ => true,
    ‘exclude_from_search’ => false,
    ‘has_archive’ => true,
    ‘query_var’ => true,
    ‘can_export’ => true,
    ‘rewrite’ => true,
    ‘capability_type’ => ‘post’,
    ‘rewrite’ => array( ‘slug’ => ‘top_ten’ ),
    );
    register_post_type( ‘top_ten’, $args );
    flush_rewrite_rules();
    }

    and for I want to change url rewriting

    like this

    add_filter( ‘post_type_link’, ‘custom_post_type_link’, 10, 3);

    function custom_post_type_link($permalink, $post, $leavename) {
    if (!gettype($post) == ‘post’) {
    return $permalink;
    }
    switch ($post->post_type) {
    case ‘top_ten’:
    $permalink = get_home_url() . ‘/top-ten-best-‘ . $post->post_name . ‘/’;
    break;
    }

    return $permalink;
    }

    but it show 404 error

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Product listing based on Custom Taxonomy’ is closed to new replies.