Support Forum » User Profile

Forum Replies Created

Viewing 12 posts - 31 through 42 (of 42 total)
  • Author
    Posts
  • in reply to: Count posts that have a related term #31432
    Rebecca RobertsonRebecca Robertson
    Participant

    Thank you, that helped!

    I had to make a few modifications as your code showed post counts for all of the taxonomy terms and I only wanted the count for the single related term.

    This is the code that works:

    <?php
    $query_destinations = new WP_query( array(
    'post_type' => 'destination',
    ) );
            
    $states = get_terms( [
    'taxonomy'     => 'state',
    'hide_empty'   => false,
    'relationship' => [
    'id'           => 'from_destination_to_state_tax',
    'from'         => get_the_ID(), // You can change from or to based on the relationship
    ],
    ] );
    
    foreach ( $states as $state ) {
    $count = $query->post_count;
    echo  $state->count . " Related Posts";
    }
    ?>         
    
    in reply to: Calling Featured Image for Custom Taxonomy #31377
    Rebecca RobertsonRebecca Robertson
    Participant

    Okay, I figured out my problem so that's solved, but I have another question that you may be able to help me with.

    I have two custom post types that are related, "single-state" and "destination". I also have a custom taxonomy called "state" that is associated with the "Destination" CPT but not the "Single State" CPT.

    Each single state post contains information about one single state, such as Arizona, California, Idaho, etc. Destination posts are about places within a state, such as favorite camping spots, good places to eat, etc.

    Every "Destination" has one "state" taxonomy, so, for instance, a post called "Visiting Grand Canyon West" would have the taxonomy of "Arizona" because Grand Canyon West is in Arizona.

    Now on the Single State Post for Arizona I want to show the number of posts that are in the "State" taxonomy of "Arizona".

    So far what I've tried shows the post count for all of the states on every single state post, but I only want the count for the posts with the same "state" taxonomy as the single state post (destinations "tagged" Arizona posts on the single post about Arizona, destinations "tagged" California on the single post about California, etc.).

    This is the code I'm using

    
    <?php
    $states = get_terms(
    'state', // your custom taxonomy slug
    array(
    'hide_empty' => false,
     ));
    
    foreach ( $states as $term ) {
    echo $term->slug . ' - ' . $term->count . '<br>';
    }
     ?>
    

    I'm really hoping that I can do this without having to use dozens of if/else statements.

    in reply to: Calling Featured Image for Custom Taxonomy #31347
    Rebecca RobertsonRebecca Robertson
    Participant

    Oh, and it shows the exact same cover image on every page, which is not at all helpful.

    in reply to: Calling Featured Image for Custom Taxonomy #31346
    Rebecca RobertsonRebecca Robertson
    Participant

    Thank you, that worked perfectly! Now onto the next problem, I really can't wait until you get the taxonomy tutorial done!

    I need to put the same image as well as a cover image on the top of the archive page, just like the last part of the categories tutorial.

    The Field Group ID for the cover image is "cover-image-for-state", the field ID for the image url is "cover-image-url", and the field ID for the cover image is "state_cover_image".

    I've tried modifying the code from that step of the tutorial as:

    
    <?php
        $state = get_terms( 'state' );
        $background_image = get_term_meta( $state[0]->term_id, 'state_cover_image', true );
        if ($background_image) {
            $link_image = wp_get_attachment_image_src( $background_image, 'full' );
            $link_image_source = $link_image[0];
        }
        else {
            $link_image_source = get_term_meta( $state[0]->term_id, 'cover-image-url', true );
        }
    ?>   
    

    and calling the image with:

    
    <div id="cover" class="pageHeader cover-area">
        <div class="cover-image">
             <img class="thumbnail-cat" src="<?php echo $link_image_source ?>">
        </div>
    </div>
    

    but that isn't working.

    For absolutely unknown reasons, taking this code:

    
    <?php 
        $paged = get_query_var('paged') ? get_query_var('paged') : 0;
        $states = get_terms( array(
            'taxonomy' => 'state',
            'hide_empty' => false,
            'orderby' => 'name',
            'order' => 'ASC',
            'posts_per_page' => '-1',
            'paged' => $paged,
            'exclude' => array('1289','1290','1291','1292','1294','1295','1296','1298','1299','1300','1301','1302','1303','1304','1305','1306','1307','1308','1309','1310','1311','1312','1313','1314','1315','1316','1317','1318','1320','1321','1323','1324','1325','1326','1327','1319','1322'),
        ));
        ?>
    

    from the previous page and cutting it down to this:

    
    <?php
        $state = get_terms( array(
            'taxonomy' => 'state',
            'exclude' => array('1296','1301'),
        ));
        $background_image = get_term_meta( $state[0]->term_id, 'state_cover_image', true );
        if ($background_image) {
            $link_image = wp_get_attachment_image_src( $background_image, 'full' );
            $link_image_source = $link_image[0];
        }
        else {
            $link_image_source = get_term_meta( $state[0]->term_id, 'cover-image-url', true );
        }
    ?>   
    

    does work. But if I take any part of the remaining exclude statement out it stops working. I don't understand that at all because I shouldn't need an exclude statement or an array on this page!

    What am I doing wrong?

    in reply to: If Then Question #27707
    Rebecca RobertsonRebecca Robertson
    Participant

    Thank you!

    in reply to: Selecting Post Formats #24907
    Rebecca RobertsonRebecca Robertson
    Participant

    Thank you.

    in reply to: Selecting Post Formats #24891
    Rebecca RobertsonRebecca Robertson
    Participant

    This is the part I'm confused about. Where do I put action hook and function?

    in reply to: Link to and Show Author Profiles #23701
    Rebecca RobertsonRebecca Robertson
    Participant

    Sorry about this, but before I forget. I've created the login page, but how do I do the logout link?

    in reply to: Only Admin to Add New Users #23603
    Rebecca RobertsonRebecca Robertson
    Participant

    Ah! Thank you, that was the issue! Works beautifully!

    in reply to: Only Admin to Add New Users #23599
    Rebecca RobertsonRebecca Robertson
    Participant

    Screenshot

    in reply to: Only Admin to Add New Users #23598
    Rebecca RobertsonRebecca Robertson
    Participant

    This is what I see:
    https://drive.google.com/file/d/1glH-O6zJey3GAjiS3Zp0kKAfn4vefuN4/view?usp=sharing

    Here is the shortcode:
    <?php echo do_shortcode('[mb_user_profile_register role="author" label_submit="Add Author" confirmation="The new author has been added successfully."" show_if_user_can="create_users"]'); ?>

    I've created 1 new author using the form, so it works, but the confirmation is the default one rather than the one I put in the shortcode and when I added a password it told me that I already have a password for the site. Mostly it's fine as I'm the only one who will be using this form, I just hate not knowing what I'm doing wrong.

    Basically what I want is to add the first, last and user names, email, role and temporary password. Then a link to their page should be sent to them and they can change what they need to and add all the other stuff.

    in reply to: Only Admin to Add New Users #23596
    Rebecca RobertsonRebecca Robertson
    Participant

    Thank you!

    The form is showing my name and password, is there a way for it to be blank? If not, I can work with that.

    Thanks again for the very quick reply!

Viewing 12 posts - 31 through 42 (of 42 total)