最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to echo a string in custom posts args from a custom field?

programmeradmin1浏览0评论

i am using a function (maav_portfolio_infinite_loading) to load more custom posts on a page via ajax.

I want to be able to load only from a specific category that i can set it on the main portfolio page. I created the field and everything works except the category filter. If i introduce it manually ('portfolio_category' => web,) it works but when i try to echo it, for some reason it doesn't work.

I need to echo the $select_categ in 'portfolio_category'.

the function bellow is in functions.php.

function maav_portfolio_infinite_loading() {
$select_categ = Maav_Helper::get_post_meta( 'select_categ', '' );

    $args = array(
        'post_type'      => $_POST['post_type'],
        'posts_per_page' => $_POST['posts_per_page'],
        'orderby'        => $_POST['orderby'],
        'order'          => $_POST['order'],
        'paged'          => $_POST['paged'],
        'portfolio_category' => $select_categ,
        'post_status' => array('publish') 
    );

    $style             = isset( $_POST['style'] ) ? $_POST['style'] : 1;
    $overlay_style     = isset( $_POST['overlay_style'] ) ? $_POST['overlay_style'] : 'inner-text';
    $i                 = ( $args['paged'] - 1 ) * $args['posts_per_page'];
    $count             = $_POST['count'];
    $image_size        = $_POST['image_size'];
    $overlay_animation = $_POST['overlay_animation'];
    $maav_query   = new WP_Query( $args );

    if ( $maav_query->have_posts() ) :
        include( get_template_directory() . '/loop/portfolio/style-' . $style . '.php' );
    endif;
    wp_reset_postdata();
    wp_die();
}

Thank you in advance!

i am using a function (maav_portfolio_infinite_loading) to load more custom posts on a page via ajax.

I want to be able to load only from a specific category that i can set it on the main portfolio page. I created the field and everything works except the category filter. If i introduce it manually ('portfolio_category' => web,) it works but when i try to echo it, for some reason it doesn't work.

I need to echo the $select_categ in 'portfolio_category'.

the function bellow is in functions.php.

function maav_portfolio_infinite_loading() {
$select_categ = Maav_Helper::get_post_meta( 'select_categ', '' );

    $args = array(
        'post_type'      => $_POST['post_type'],
        'posts_per_page' => $_POST['posts_per_page'],
        'orderby'        => $_POST['orderby'],
        'order'          => $_POST['order'],
        'paged'          => $_POST['paged'],
        'portfolio_category' => $select_categ,
        'post_status' => array('publish') 
    );

    $style             = isset( $_POST['style'] ) ? $_POST['style'] : 1;
    $overlay_style     = isset( $_POST['overlay_style'] ) ? $_POST['overlay_style'] : 'inner-text';
    $i                 = ( $args['paged'] - 1 ) * $args['posts_per_page'];
    $count             = $_POST['count'];
    $image_size        = $_POST['image_size'];
    $overlay_animation = $_POST['overlay_animation'];
    $maav_query   = new WP_Query( $args );

    if ( $maav_query->have_posts() ) :
        include( get_template_directory() . '/loop/portfolio/style-' . $style . '.php' );
    endif;
    wp_reset_postdata();
    wp_die();
}

Thank you in advance!

Share Improve this question asked Apr 16, 2019 at 21:31 mThemes NetmThemes Net 11 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

What value do you get if you echo Maav_Helper::get_post_meta( 'select_categ', '' ) or the variable $select-categ?

Since manually inputting web works, check if the scope resolution operator is working. Sounds like it may be returning an empty string or undefined value.

发布评论

评论列表(0)

  1. 暂无评论