Unyson icon indicating copy to clipboard operation
Unyson copied to clipboard

Query Post Using Post Option Value Parameter

Open blackmekemeke opened this issue 12 years ago • 4 comments

I have custom post type named 'download' in my theme. I create checkbox option to set this post type as featured download, so when the checkbox checked the download post become featured download. I want to display latest featured download using this post option parameter. This is my wp query but it doesn't work.

$args=array(
        'post_type' => 'download',
        'posts_per_page'=> 10,
        'meta_query' => array(
            array(
                'key'     => 'feature_download',
                'value'   => '1'
            ),
        ),
        'ignore_sticky_posts' => 1
    );
$my_query = new wp_query($args);

Can you help me? thanks

blackmekemeke avatar Nov 02 '14 09:11 blackmekemeke

The framework saves all options in one meta key as serialized array, so you can't query by specific option id.

If you want an option to be saved as separate meta, use the save-in-separate-meta parameter.

You can set this parameter to any option

'option_id' => array(
    'type' => 'text',
    'save-in-separate-meta' => true,
),

The query for your case will be

$args = array(
        'post_type' => 'download',
        'posts_per_page'=> 10,
        'meta_query' => array(
            array(
                'key'     => 'fw_option:feature_download',
                'value'   => '1',
            ),
        ),
        'ignore_sticky_posts' => 1
    );
$my_query = new wp_query($args);

ghost avatar Nov 02 '14 10:11 ghost

I have another question, what is the conditional tag for if this page using builder not the standard WP editor. Thanks.

blackmekemeke avatar Nov 02 '14 21:11 blackmekemeke

Hi @blackmekemeke, currently it is tricky to check whether a page is built with the builder or not, we will make a helper function that will do this in a future release.

rockalife avatar Nov 03 '14 13:11 rockalife

@blackmekemeke what is the conditional tag for if this page using builder not the standard WP editor

The fw_ext_layout_builder_is_builder_post($post_id = '') helper was added in v1.4.10

ghost avatar Nov 06 '14 15:11 ghost