0

My custom posts don't have a title, rather they rely on custom fields, and all the solutions I've tried so far seem to work if the title is present.

<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

$args = array(
    'post_type' => 'people',
    'posts_per_page' => 40,
    'meta_key' => 'surname',
    'orderby' => 'meta_value',
    'order' => 'ASC',
    'paged' => $paged
);
// The Query
query_posts( $args );
?>

This should work (and it works for other custom post types that have a title), but I can't seem to get it working on the ones without. surname is a custom field on the custom post type people.

0

As far as I know, you can't actually publish a post without a title. WP might erroneously say your posts are published, but I'm pretty sure they're still viewed as drafts, which is why you don't get any post results.

First, make sure your custom post type supports your custom field:

$args = array(
    'post_type' => 'people',
    'posts_per_page' => 40,
    'meta_key' => 'surname',
    'orderby' => 'meta_value',
    'order' => 'ASC',
    'paged' => $paged,
    'supports' => array( 'title', 'editor', 'custom-fields')
);

Then, you could auto populate the title or create it from meta data:

Set post title from two meta fields

  • I've made the title auto populate from the ID, this still hasn't solved it in this case. Strange. – ScottMcGready Mar 3 '14 at 20:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.