Support

Account

Forum Replies Created

  • thank you so much john – this really worked for me, and as usual i have learnt something i’ll use again. really appreciate your persistence with this.

  • thanks john (i should just keep you on retainer here).

    i’m using the following code in the theme’s functions.php file:

    // Add Multiple Custom Post Types
    
    add_action('init', 'all_custom_post_types');
    
    function all_custom_post_types() {
      $types = array(
        // News
        array('the_type' => 'news',
              'single' => 'News',
              'plural' => 'News'),
        // Artists
        array('the_type' => 'artist',
              'single' => 'Artist',
              'plural' => 'Artists'),
        // Releases
        array('the_type' => 'release',
              'single' => 'Release',
              'plural' => 'Releases')
      );
    
    foreach ($types as $type) {
      $the_type = $type['the_type'];
        $single = $type['single'];
        $plural = $type['plural'];
      $labels = array(
          'name' => _x($plural, 'post type general name'),
          'singular_name' => _x($single, 'post type singular name'),
          'add_new' => _x('Add New', $single),
          'add_new_item' => __('Add New '. $single),
          'edit_item' => __('Edit '.$single),
          'new_item' => __('New '.$single),
          'view_item' => __('View '.$single),
          'search_items' => __('Search '.$plural),
          'not_found' =>  __('No '.$plural.' found'),
          'not_found_in_trash' => __('No '.$plural.' found in Trash'),
          'parent_item_colon' => ''
        );
        $args = array(
          'labels' => $labels,
          'public' => true,
          'publicly_queryable' => true,
          'show_ui' => true,
          'query_var' => true,
          'rewrite' => true,
          'capability_type' => 'post',
          'hierarchical' => false,
          'has_archive' => true,
          'menu_position' => 5,
          'supports' => array('title','editor','thumbnail'),
          'show_in_menu' => true,
          'show_in_nav_menus' => true,
          'taxonomies' => array( 'category' )
        );
    
        register_post_type($the_type, $args);
      }
    }

    is this what you mean?

  • thanks john,

    i’m sorry but i really don’t understand – this isn’t because you’re not explaining it well, it’s because i don’t quite have the knowledge already. i can see from the link, and from this article (i think) what needs to happen but implementing the code is a little beyond me.

    i just can’t work out how to write the function that calls the ID of the user named in the sub_field “author”?

  • thanks john,

    turns out i hadn’t gotten as far as i thought earlier – i’ve added a new user and alternated the calls in the repeater field to check the results but it seems i’m calling only one user all the time: http://wpc.matmartin.co.uk/info/.

    my guess is that i’m somehow calling the author of the page in question over the author specified in the sub field, but i can’t see how. have i missed something really obvious?

    here’s where my code is at for that part of the page template.

    <?php if( have_rows('author_profiles') ): ?>
      <div class="ca">
        <div id="pagebody">
          <h3>The Tap The Feed Team</h3>
          <?php while ( have_rows('author_profiles') ) : the_row(); ?>
          <div class="infoauthor">	
            <div class="infoauthorimg">
            <?php
              $users = get_sub_field('author');
              echo get_avatar( get_the_author_meta( 'user_email' ), apply_filters( 'twentyeleven_author_bio_avatar_size', 120 ) );
            ?>
          </div>	
          <div class="infoauthorcopy">	
            <h4 class="nopad"><a href="<?php $users = get_sub_field('author'); echo get_author_posts_url( get_the_author_meta( 'ID' ) ); ?>"><?php $users = get_sub_field('author'); echo the_author_meta( 'display_name' ); ?></a></h4>
            <p class="nopad"><?php the_sub_field('title'); ?></p>
            <p class="nopad"><a href="<?php $users = get_sub_field('author'); echo the_author_meta( 'user_url' ); ?>" target="_blank"><?php $users = get_sub_field('author'); echo the_author_meta( 'user_url' ); ?></a></p>
            <p><a href="http://twitter.com/<?php $users = get_sub_field('author'); echo the_author_meta( 'twitter' ); ?>" target="_blank">@<?php $users = get_sub_field('author'); echo the_author_meta( 'twitter' ); ?></a></p>
            <p><?php $users = get_sub_field('author'); echo the_author_meta( 'description' ); ?></p>	
          </div>
        </div>
        <?php endwhile; ?>
      </div>
    </div>
    <?php else : endif; ?>

    the role of each author (editor, sub-editor etc.) is a text field within the same repeater, and this is being called correctly, so i’m pretty sure the repeater is running as it should but i just haven’t targeted the author info within it, which would cause the code to fall back on the metadata for the page author i guess.

    as you can see, i’ve not added in those checks yet but your suggestion is pretty clear and makes sense to me. i’m assuming both for this and for the above (line 14) that if i have to specify the author ID in a changing repeater field then get_author_posts_url( get_the_author_meta( ‘ID’ ) ); will call it from the author in the sub field if used correctly?

    the trick is using it correctly, right?

    thanks again.

  • thanks john,

    this is super-useful, and as you can see here i’ve managed to pull what i need and style it accordingly as a result – for the record here’s the code that worked for me:

    <div class="infoauthorimg">
      <?php 
        $users = get_sub_field('author');
        echo get_avatar( get_the_author_meta( 'user_email' ), apply_filters( 'twentyeleven_author_bio_avatar_size', 120 ) );
    ?>
    </div>	
    <div class="infoauthorcopy">	
      <?php $users = get_sub_field('author'); ?>
      <h4><a href="#"><?php echo the_author_meta( 'display_name' ); ?></a></h4>
      <p class="nopad"><a href="<?php echo the_author_meta( 'user_url' ); ?>" target="_blank"><?php echo the_author_meta( 'user_url' ); ?></a></p>
      <p><a href="http://twitter.com/<?php echo the_author_meta( 'twitter' ); ?>" target="_blank">@<?php echo the_author_meta( 'twitter' ); ?></a></p>
      <p><?php echo the_author_meta( 'description' ); ?></p>	
    </div>

    so there are a couple of details which are a little beyond me – as you can see i’ve got a blank hyperlink there around the display_name – i’d like to be grabbing that author’s post archive url for there but it doesn’t seem to be in the array (see screenshot).

    i’d also really like to add some conditionals to the user_url and twitter data, so that they aren’t called as blank spaces if they don’t exist.

    any ideas on how i can fine tune this now?

    thanks so much – amazingly helpful as usual!

    m

  • well, it will certainly be of use to me in the future, too! thanks john.

  • john, firstly let me apologise for not thanking you sooner – for some reason i didn’t receive a notification that you had replied and have only just come back here to re-read everything because i still hadn’t found a solution.

    now: i pasted your code in place of mine, having seen your example working, and it’s working fine for me. thank you so much. the difference is simply in the way in which you’ve targeted the query, correct? with this line?

    if (is_admin() || !$query->is_home() || !$query->is_main_query()) {
    return;

    i can’t thank you enough for being so persistent in your help tracking this down.

    the second filter is designed to prevent an empty page at the very end of the paginated feed, as per this article: https://codex.wordpress.org/Making_Custom_Queries_using_Offset_and_Pagination – however, everything seems to be fine without it, so i’m going to leave it out!

  • hey john, thanks for the tenacity here!

    so yes, i was surprised too, but this is from the last email i got on that subject from ACF support:

    I have verified the issue with pre_get_posts. Unfortunately, there is no workaround for the same at the moment.
    The only option would be to replace the implementation of the ‘pre_get_posts’ with an alternative.
    We have had quite a number of similar cases and the developer is already aware of this issue.

    so yes, as precisely as i can – i have a static homepage at http://veggiemagnifique.com which contains two loops, one to show the most recent post in its entirety, and another to show extracts from the next four, totalling the most recent five posts.

    i have then been trying to begin the blog archives at http://veggiemagnifique.com/blog with an offset of 5, designated within wordpress as the posts page. it’s important that this query is paginated. right now it goes back to the most recent post and starts from there. adding an offset to the query as i’ve done on the homepage would break pagination, and as we’ve discovered, adding one in the way WP suggest, via pre_get_posts has so far offset all repeater fields across the site, although it has had the effect i wanted with regard to offset and pagination on the blog.

    with the exception of the homepage we’re showing 16 posts per page. this is because the layout on the category pages requires it (although i could conceivably alter the queries in the category template to keep this number there if the WP settings were changed).

    the reason i haven’t done what you suggest, although i follow the logic clearly, is because the homepage displays the first post differently to the others. my instinct was to create a bespoke loop for that. maybe there’s a better way to target only the first post in a loop?

    if i could do that i wouldn’t even need the 301 redirect i think, i could just make the posts page the homepage and it would be page 1 of the blog.

  • thanks again – makes sense. i’ve been tinkering with similar things but nothing has rectified the issue with repeater fields, no matter how precisely i target the query. even

    if (!is_admin() &&
        $query->is_main_query() && 
        !empty($query->query_vars['post_type']) && 
        $query->query_vars['post_type'] == 'post') {
    }

    doesn’t leave the repeaters alone.

    i suspect it’s something that might need changing within the plugin. ACF support have told me it’s a “known issue” but i’ve been holding out to discover some kind of workaround.

    i really appreciate your input. thank you.

  • thanks john, i appreciate the reply.

    i think i understand what you’re suggesting in theory but i’m struggling to put it into practice – i don’t quite understand the syntax of the code well enough i guess.

    i’m stumbling over nailing the correct query because of the fact that the blog uses a static front page and as such the query i am looking to affect is on the posts page. as far as i can tell is_home should target that (and did perfectly apart from the effect it had on the repeater fields), but of course your additional code would need to be added into that and i’m not sure exactly how.

    it doest appear that i can simply stack those if checks one above the other. do they need to be combined into a single statement?

    as far as what i’m trying to do is concerned, it really is just a case of the posts page having an initial offset of 5 and still being paginated, but without affecting repeaters.

Viewing 10 posts - 26 through 35 (of 35 total)