[Just learning] How to select on basis of CustomField?
-
Hello,
I am just learning how to create a plugin, and for this I want to edit the frontpage query so that it will exclude all posts where the custom field “myCustomField” equals 1.
For inspiration I found some code on this page:
function exclude_category( $query ) { if ( $query->is_home() && $query->is_main_query() ) { $query->set( 'cat', '-3' ); } } add_action( 'pre_get_posts', 'exclude_category' );
This excludes all posts which have the term_id (category id?) set to 3. I now want to exclude all posts which have “myCustomField” set to 1.
I tried changing
$query->set( 'cat', '-3' );
to
$query->set( 'myCustomField', '-1' );
but unfortunately that doesn’t work.
Does anybody know how I can select on the basis of custom fields? All tips are welcome!
- The topic ‘[Just learning] How to select on basis of CustomField?’ is closed to new replies.