Forum Replies Created

Viewing 12 replies - 1 through 12 (of 12 total)
  • pcgardner

    (@pcgardner)

    Hi @keraweb

    Thanks for your reply. Perhaps I’m being dim, but I don’t see how this can work for a new book form with no data. Or do I have to create a new PODS post in PHP, get its post_id, set its fields using update_post_meta() or whatever, and then create the PODS form to edit the ‘new’ post? I can do that (I think!), but I was hoping there was a simpler way to pass values to the empty PODS form fields.

    All the best, Phil

    Thank you very much for that code. It’s taken me a while to get around to implementing it, but I’ve now got it working. I had to make a few changes:

    add_filter( 'a_z_listing_item_index_letter', 'ignore_quotes_in_a_z_listing', 10, 3 );
    
    function ignore_quotes_in_a_z_listing( $indices, $item, $type ) {
        if ( 'terms' === $type ) {
            $title = $item->name;
        } else {
            $title = get_the_title( $item );
        }
        if ( ( 0 === strpos( $title, '"' ) ) || ( 0 === strpos( $title, '\'' ) ) ) {
    	return [ mb_substr( $title, 1, 1 ) ];
        } else {
    	return $indices;
        }
    }

    Notes

    [1] In line 2 of the function it must be ‘terms‘, not ‘term’; it took me a while to spot that!

    [2] I had to test the first character of $title (so 0, not false), because your code would have caused Land’s End to be alphabetized under ‘A’.

    pcgardner

    (@pcgardner)

    Thanks to your help I now have a fully working index with cross-references incorporated, and thought I would share my customized template in case anyone else wants to do something similar.

    I set up two custom taxonomies (using PODS, but that shouldn’t make any difference). The first is ‘subject’, which has no custom fields and works like categories or tags. The second is ‘cross_reference’, with one custom field called ‘target_subjects’. For example, a cross-reference with the title ‘dunnock’ might have ‘garden birds’ in its target_subjects field.

    Here is my a-z-listing.php template file; it is in the root of my theme folder. The customized section is indicated by comments.

    <?php
    /**
     * Default multicolumn template for the A-Z Listing plugin
     *
     * This template will be given the variable <code>$a_z_query</code> which is an instance
     * of <code>A_Z_Listing</code>.
     *
     * You can override this template by copying this file into your theme
     * directory.
     *
     * @package a-z-listing
     */
    
    /**
     * This value indicates the number of posts to require before a second column
     * is created. However, due to the design of web browsers, the posts will flow
     * evenly between the available columns. E.g. if you have 11 items, a value of
     * 10 here will create two columns with 6 items in the first column and 5 items
     * in the second column.
     */
    $_a_z_listing_minpercol = 10;
    ?>
    <div id="az-tabs">
    	<div id="letters">
    		<div class="az-letters">
    			<?php $a_z_query->the_letters(); ?>
    		</div>
    	</div>
    	<?php if ( $a_z_query->have_letters() ) : ?>
    	<div id="az-slider">
    		<div id="inner-slider">
    			<?php
    			while ( $a_z_query->have_letters() ) :
    				$a_z_query->the_letter();
    				?>
    				<?php if ( $a_z_query->have_items() ) : ?>
    					<?php
    					$item_count  = $a_z_query->get_the_letter_count();
    					$num_columns = ceil(
    						$item_count / $_a_z_listing_minpercol
    					);
    					?>
    					<div class="letter-section"
    						id="<?php $a_z_query->the_letter_id(); ?>">
    						<h2 class="letter-title">
    							<span>
    								<?php $a_z_query->the_letter_title(); ?>
    							</span>
    						</h2>
    						<?php $column_class = "max-$num_columns-columns"; ?>
    						<ul class="columns <?php echo $column_class; ?>">
    							<?php
    							while ( $a_z_query->have_items() ) :
    								$a_z_query->the_item();
    								?>
    								<li>
    /** CUSTOMIZED CODE BEGINS */
    								<?php 
    								$term = $a_z_query->get_the_item_object( 'I understand the issues!' ); 
    								if ( 'cross_reference' === $term->taxonomy ) : ?>
    								<?php $a_z_query->the_title(); ?>:<em> see </em>
    								<?php echo get_term_meta( $term->term_id, '', false )["target_subjects"][0] ; ?>
    								<?php else : ?>
    									<a href="<?php $a_z_query->the_permalink(); ?>">
    										<?php $a_z_query->the_title(); ?>
    									</a>
    								<?php endif ?>
    /** CUSTOMIZED CODE ENDS */
    								</li>
    							<?php endwhile; ?>
    						</ul>
    						<div class="back-to-top">
    							<a href="#letters">
    								<?php _e( 'Back to top', 'a-z-listing' ); ?>
    							</a>
    						</div>
    					</div>
    					<?php
    				endif;
    			endwhile;
    			?>
    		</div>
    	</div>
    </div>
    <?php else : ?>
    	<p>
    		<?php
    		esc_html_e(
    			'There are no posts included in this index.',
    			'a-z-listing'
    		);
    		?>
    	</p>
    	<?php
    endif;
    • This reply was modified 8 months ago by pcgardner. Reason: Improved accuracy
    pcgardner

    (@pcgardner)

    But the documentation says:

    taxonomy: sets the taxonomy containing the terms specified in the terms=”” option
    Default value: unset.
    May only contain one value.
    Must be the slug of the taxonomy.

    Presumably the documentation is out of date. If I’d known that I could have saved myself quite a bit of time!

    Anyway, thank you very much for your help. I’ll experiment with the code along the lines you suggest.

    pcgardner

    (@pcgardner)

    I don’t think this is the plugin you need. More appropriate would be All-in-One WP Migration or Duplicator.

    pcgardner

    (@pcgardner)

    Thank you – that’s ingenious! I’m afraid I don’t quite see how it would work, though. Presumably my custom taxonomy, subjects, would have to have a custom field called aliases which if the term is a X-ref would contain a list of comma-separated alias subjects. That’s okay, I think.

    The problem is that each of those aliases would have to actually function in the same way as it does in its proper place in the list – it would have to link to all the posts that had the alias subject. Wouldn’t you have to use another loop, to find those posts? That could be very resource-hungry.

    To use my previous example, an entry might look like this:
    Thrush see Turdus turdus; garden birds.

    If only it were possible to include two taxonomies in one listing! Then I could combine the subject taxonomy with an alias taxonomy. The alias taxonomy wouldn’t have any posts, it would simply have the entire cross-reference as its title (unlinked – the user would have to find the item referred to manually, as with a book index).

    • This reply was modified 8 months ago by pcgardner.

    In the documentation this filter hook is marked as deprecated. Is this simply because its name is to be changed, or will it disappear altogether?

    Thank you! That’s unbelievably straightforward. As I already had a custom template I just added two lines at the start:

    <?php
    /*
     * The email address has been verified, so
     * mark the participant as 'approved'
     */
    $participant_id = $this->participant_values['id'];
    Participants_Db::write_participant( array('approved' => 'yes'), $participant_id );
    
    /*
     * First, check for the value that determines what kind of 
     * record edit form to show
     */
    $type = $this->participant_values['source_page'];
    /*
     * Now, show the record edit form for that type
     */
    switch ( $type ) {
       case 'sign-our-letter-laity':
          echo do_shortcode('[pdb_record groups="main,church_of_england,laity"]');
          break;
       case 'sign-our-letter-clergy':
          echo do_shortcode('[pdb_record groups="main,church_of_england,clergy"]');
          break;
       case 'sign-our-letter-anglican-communion':
          echo do_shortcode('[pdb_record groups="main,anglican_communion"]');
          break;
    }
    

    And it just works!

    I couldn’t find a way to donate so I’ve bought a site licence for the Email Expansion add-on, which I shall find useful. Thank you again.

    Oh! Yes, with that change it now works fine – thank you. Frustrating that I’ve spent hours struggling with it.

    I see the tutorial page has been corrected now. It didn’t occur to me that the original code might be wrong, as the comments suggested that at least some people had been able to use it successfully. Presumably the plugin coding has been updated since then.

    May I ask your help about something connected? I would like the Private Link, when clicked, to automatically change the corresponding record so that the Approved field is set to ‘yes’. This would make the Private Link verify the email address without the user or the admin needing to do anything else.

    Can this be done by adding some code to the beginning of pbd-record-usertype.php that would change the database record without the user submitting the form? If so, can you tell me how to do this?

    Thanks again for all your help and for such a wonderful plugin. I shall make a donation.

    Phil

    No, it is correct in all the records – I’ve tried several.

    Thanks very much for your helpful response.

    This is a development site, so WP_DEBUG is on, but it is not outputting to the screen. The debug output goes to the debug.log file in wp-content.

    I am using the access code. In the admin ‘List Participants’ page I click on the access code for one of the records, which takes me directly to the Edit Record page for that record, with a URL like this: https://dev.cofe-equal-marriage.org.uk/support-the-campaign/sign-our-letter/open-letter-edit-your-record/?pid=W7K4K

    The relevant part of the HTML output of that pages looks like this:

    <div class="entry-content">
    		<p>If you have lost your private link to access your record, please <a href="https://dev.cofe-equal-marriage.org.uk/support-the-campaign/sign-our-letter/private-link-reminder-request/">click here</a> to request a reminder; your link will be emailed to you.</p>
    <!-- template: equal/templates/pdb-record-usertype.php -->Source page: <!-- end template: equal/templates/pdb-record-usertype.php -->
    	</div>

    That looks complete to me, not as if an error has truncated the output. And the rest of the page (the footer) is displayed correctly.

    It seems that $type is empty when it ought to contain (in the above example) the value sign-our-letter-laity, the slug of the source page, which displays correctly in List Participants. Because $type is empty, the echo do_shortcode commands are never called. So the output is as expected.

    The crucial question must be, why is $type empty?

    By emptying debug.log as you suggested, I have discovered that the error
    [19-Apr-2019 20:59:31 UTC] PHP Warning: session_start(): Cannot start session when headers already sent in /var/www/clients/client54/web203/dev/wp-content/plugins/participants-database/vendor/wp-session-manager/wp-session-manager.php on line 46
    occurs when I load the List Participants page. No further errors are added to debug.log when I access the Edit record page.

    pcgardner

    (@pcgardner)

    That’s good to know! It would be so much easier to do what I want using linked tables that I think it’s worth my waiting until the feature is available. Is there any chance you could let me know when it’s ready?

Viewing 12 replies - 1 through 12 (of 12 total)