• Resolved Mango123

    (@mango123)


    Hi there,

    I’ve created a custom field which links to the page object of another page using the plugin advanced custom fields. I now want to use query_posts to return all of my posts that link to a particular page using that page object custom field.

    The value I would like to filter is found using:
    `$field = get_field(‘on_page’); // my custom field
    echo $field->post_title;`

    Can I use $field->post_title as a parameter in query_posts? If so is it possible to show me how I would do it?

    Many thanks,

    Ben

Viewing 2 replies - 1 through 2 (of 2 total)
  • Please explain what you want as the results of the query_posts()?

    Thread Starter Mango123

    (@mango123)

    Hi vtxyzzy,

    Thanks for your question, I wanted to filter query_posts so it would only return results based on a custom field value.

    I managed to find out that I could use the object ID of the custom field. So for ‘meta_value’ I could use the value found from $field->ID.

    The code I ended up using was:

    wp_reset_query();
    		$args = array(
    			'post_type' => 'feature',
    			'orderby' => 'date',
    			'order' => 'ASC',
    			'posts_per_page' => 4,
    			'meta_key' => 'on_page',
    			'meta_value' => 2
    		);
    		query_posts( $args );

    The meta_value I found by printing $field->ID.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to use custom object field value as parameter in query_posts’ is closed to new replies.