Forum Replies Created

Viewing 15 replies - 1 through 15 (of 44 total)
  • Buchanan Webmaster

    (@jeffsydor-bipc)

    I too would like to know this. I mainly would like to know where I can find or how to query my database to find specific authors. I’ve looked everywhere I can think of in the DB and can’t find where coauthors are listed.

    I need to change the format of dozens of usernames and when I do this, many of the posts attributed to those coauthors get disconnected somehow. I need to find the old username in my DB and replace them with the new username.

    If not in the DB, is there a function that I can write up that will do this?

    Any help would be appreciated. Thanks!

    Thread Starter Buchanan Webmaster

    (@jeffsydor-bipc)

    Nope, nevermind! I just realized there weren’t any tags applied to the posts. Silly me. lol

    Thread Starter Buchanan Webmaster

    (@jeffsydor-bipc)

    @diondesigns I tried adapting this for my tags section too. But for some reason it’s not working here. Any ideas?

    function list_search_tags() {
       $tagTmp = array();
       $tagLinks = '';
      
       // Start The Loop
          while (have_posts()) : the_post();
             $post_tags = get_the_tags();
    
             foreach ($post_tags as $tag) : $tagID = $tag->term_id;
    
                if (empty($tagTmp[$tagID])) :
                   $tagTmp[$tagID] = 1;
                   $tagURL = get_tag_link($tagID);
                   $tagName = $tag->name;
                   $tagLinks .= '<li><a class="tag" href="' . $tagURL . '">' . $tagName . '</a></li>';
                endif;
      
          endforeach;
       endwhile;
    
       echo $tagLinks;
      
    }
    
    Thread Starter Buchanan Webmaster

    (@jeffsydor-bipc)

    @diondesigns thank you! This worked perfectly!

    Now I think I need to find a way to sort them by number of occurrences. But now I need to understand why yours works!

    Thank you!

    Thread Starter Buchanan Webmaster

    (@jeffsydor-bipc)

    I tried commenting it out and received this error:

    Notice: Trying to get property ‘ID’ of non-object in /…/wp-content/plugins/sassy-social-share/includes/class-sassy-social-share-shortcodes.php on line 153

    This code is the elseif:

    elseif ( get_permalink( $post -> ID ) ) {
    $target_url = get_permalink( $post -> ID );
    $post_id = $post -> ID;}
    
    Thread Starter Buchanan Webmaster

    (@jeffsydor-bipc)

    I don’t know if this helps or not, but after further tinkering, it looks like my array is actually an array with multiple arrays inside it. Could this be what’s causing the duplication? Can these arrays be pulled out into the root array?

    Thread Starter Buchanan Webmaster

    (@jeffsydor-bipc)

    So I’m probably way off here, but this is what I tried to do. I figured that I could create the empty array $uniqueCats first, start the loop to create the string for each list item and store that string into the empty array if it didn’t already exist in there.

    Then, I would separate new array of strings and output each as a unique item. Obviously this didn’t work, but I’m not sure if this was worth sharing or not.

    function list_search_cats() {
      // Start the Loop
      $uniqueCats = array();
      while ( have_posts() ) : the_post();
      
        $cats = get_the_category();
      
        foreach($cats as $cat) :
          $catLink = get_category_link($cat->cat_ID);
          $catName = $cat->cat_name;
          $newCat = '<li><a class="tag" href="'. $catLink .'">' . $catName . '</a></li>';
          
          if (!in_array($newCat, $uniqueCats)) : array_push($uniqueCats, $newCat);
          endif;
        endforeach;
      
        foreach($uniqueCats as $uniqueCat) :
          echo $uniqueCat;
        endforeach;
      
      endwhile;
    }
    Thread Starter Buchanan Webmaster

    (@jeffsydor-bipc)

    Hmm it seems like the variable $cat is no longer recognized after that.

    I get the following errors:
    Trying to get property ‘cat_ID’ of non-object … line 114
    Trying to get property ‘cat_name’ of non-object … line 114

    That line is the echo:
    echo '<li><a class="tag" href="'.get_category_link($cat->cat_ID).'">' . $cat->cat_name . '</a></li>';

    Thread Starter Buchanan Webmaster

    (@jeffsydor-bipc)

    Thank you for the explanation, so here’s what I’ve got:

    I have a site that will have traditional blog posts and pages. I also am using a plugin that (I am assuming) is creating a custom post type for downloadable documents.

    Further, I will also be creating static content similar to posts that will have different features (i.e. no comments, different headers etc.). This content would need to not be mixed up with typical blog posts. Also, I’ll have a section of repeatable items that would just be a thumbnail, a title and a link for external links. An example of this would be located here: https://wp19.knowgreaterpartnership.com/resources/

    In order to easily separate the content from blog posts and pages, would this be a better usage of custom post types, rather than making custom taxonomies for “resources”, “ext-links”, “definitions” etc.?

    Sorry for the wordy response, I just can’t spend more time on something like this, when it could be done better another way.

    Thanks

    Thread Starter Buchanan Webmaster

    (@jeffsydor-bipc)

    would it be better to do a custom post type or custom taxonomy here?

    Thread Starter Buchanan Webmaster

    (@jeffsydor-bipc)

    Thanks. But I have no idea what that means.

    Thread Starter Buchanan Webmaster

    (@jeffsydor-bipc)

    thanks @bcworkz,

    Unfortunately that didn’t help. My theme is built from the ground up. Does this help? I’ll include the function that includes the custom taxonomy. In this case the i_am is the taxonomy name.

    function add_iam_taxonomies() {
    	// Add new taxonomy, make it hierarchical (like categories)
    	$labels = array(
    		'name'              => _x( 'I Ams', 'taxonomy general name', 'textdomain' ),
    		'singular_name'     => _x( 'I Am', 'taxonomy singular name', 'textdomain' ),
    		'search_items'      => __( 'Search I Ams', 'textdomain' ),
    		'all_items'         => __( 'All I Ams', 'textdomain' ),
    		'parent_item'       => __( 'Parent I Am', 'textdomain' ),
    		'parent_item_colon' => __( 'Parent I Am:', 'textdomain' ),
    		'edit_item'         => __( 'Edit I Am', 'textdomain' ),
    		'update_item'       => __( 'Update I Am', 'textdomain' ),
    		'add_new_item'      => __( 'Add New I Am', 'textdomain' ),
    		'new_item_name'     => __( 'New I Am Name', 'textdomain' ),
    		'menu_name'         => __( 'Immigration I Ams', 'textdomain' ),
    	);
      
    
    	$args = array(
    		'hierarchical'      => true,
    		'labels'            => $labels,
    		'show_ui'           => true,
    		'show_admin_column' => true,
    		'query_var'         => true,
    		'rewrite'           => array( 'slug' => 'i-am' ),
    		'show_in_rest'      => true, // need to show this in order for option to display under the 'Document' panel in a post
    	);
    
    	register_taxonomy( 'i_am', array( 'post', 'i_am' ), $args );
    }
    Thread Starter Buchanan Webmaster

    (@jeffsydor-bipc)

    Then you should not mark this as resolved. That’s misleading to others, like @imdielawn, that may be looking for this solution.

    Thread Starter Buchanan Webmaster

    (@jeffsydor-bipc)

    Okay, here’s where I’m at with this as of now. I’m unsure how to get the duplicate results to be filtered out. Which is the top priority. If I can get this to also sort by count, that would be a bonus.

    Live Sample

    As you can see from the above link, I’m successfully pulling in all the relevant categories and tags of the current search and they are coming in in the chronological order of the posts.

    Here’s the page code:

    <div class="widget rel-categories">
      <h4>Popular Categories</h4>
      <div class="side-content">
        <ul>
          <?php list_search_cats(); ?>
        </ul>
      </div>
    </div>
    <div class="widget rel-tags">
      <h4>Popular Tags</h4>
      <div class="side-content">
        <ul>
          <?php list_search_tags(); ?>
        </ul>
      </div>
    </div>

    My functions.php file:

    // Find all search result categories
    function list_search_cats() {
      // Start the Loop
      while ( have_posts() ) : the_post();
      
        $categories = get_the_category();
      
        foreach($categories as $category) :
          echo '<li><a class="tag" href="'.get_category_link($category->cat_ID).'">' . $category->cat_name . '</a></li>';
        endforeach;
      
      endwhile;
      
    }
    
    // Find all search result tags
    function list_search_tags() {
      // Start the Loop
      while ( have_posts() ) : the_post();
      
        $tags = get_the_tags();
      
        foreach($tags as $tag) :
          echo '<li><a class="tag" href="'.get_tag_link($tag->term_id).'">' . $tag->name . '</a></li>';
        endforeach;
      
      endwhile;
      
    }
    Thread Starter Buchanan Webmaster

    (@jeffsydor-bipc)

    No this has not been answered.

Viewing 15 replies - 1 through 15 (of 44 total)